Urgent.News

What's breaking now, across thousands of outlets.

Tech

Merging Two Messy CSVs: The Key Problems Excel Formulas Hide From You

Merging Two Messy CSVs: The Key Problems Excel Formulas Hide From You You have two spreadsheets. One is your export, one is the client's. Someone says "just merge them on the ID column." That sentence has caused more quiet data disasters than any schema migration, because it assumes three things that are never true: the IDs match, the columns mean the same thing, and the rows are unique. I…

Merging two messy CSV files often leads to quiet data disasters that stem from hidden assumptions, according to a report on merging CSV files. The first mistake is assuming the ID column is a reliable key, as it may have different names or formatting in each file. To avoid this, count distinct values and compare the sets before merging.

The second issue arises from invisible keys, such as trailing spaces or different number formats, which can be fixed by trimming, casting, and casefolding both sides before joining. The third problem is that uniqueness is not guaranteed; a single left table may expand from 1,000 rows to 1,400 after merging, causing inflated sums.

To address this, run `df[ id ].is_unique` on both sides and check for duplicates. The fourth issue is the choice of merge type, which depends on the deliverable's requirements. Inner merges drop unmatched rows, left merges keep original rows and nulls from the other file, and outer merges keep everything. Explicitly state the merge type and log the dropped rows.

Lastly, dates can be represented in multiple formats, so parse them with explicit formats to avoid confusion. The recommended workflow is to load files raw, normalize keys, assert uniqueness, merge with explicit instructions and indicators, and count before, after, matched, and dropped rows. This process ensures accurate reconciliation and clear communication with clients when totals do not match.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Touch Grass: An App That Pays You to Go Outside

Why I built it "Touch grass" is what the internet tells people who spend too much time online. I turned the joke into a game: finish small outdoor quests, prove it with a photo, and earn rewards.

  • Touch Grass app rewards users for outdoor activities
  • Users complete tasks, take photos, earn points
  • App hosted on single HTML file with limited features

More from Sunday 11 October →