POST 1 of 5 MorningAI/MLConcept
Real data is messy. Plan for that.
Almost every tutorial dataset is clean. Iris, MNIST, Boston Housing, Titanic — all curated, all consistent, all ready for sklearn out of the box. They're useful for learning algorithms; they're misleading about the actual job. Real data is messy. Always. It has: Mixed-type columns. The 'price' column is sometimes '12.99', sometimes '12,99' (European decimal), sometimes '$12.99', sometimes 'NA', sometimes empty string. Pandas reads this as object dtype, which kills NumPy's speed. Inconsistent dates. '2024-01-01', '01/01/24', '01-Jan-2024', None, '2024-01-32' (yes, 32, real bug from a real dataset). Each format hides date arithmetic until parsed. Duplicates that aren't byte-identical. Same person registered twice with slightly different email capitalisation, slightly different phone number formats. Drop_duplicates() catches none of them. Free-text categories with typos and case. 'New York', 'new york', 'New york', 'NewYork', 'NY' — five strings, one city. Group-bys treat them as five categories. Extreme outliers from copy-paste. Someone pasted a number with the wrong number of zeros. Now your 'age' column has a 99,000-year-old. The mean is meaningless until you handle it. Missing values that aren't NaN. The original system used '-1' or '999' or empty string for missing. Pandas reads these as values. Mean and std are computed over them. The rule that drops out — budget 60% of any data project for cleaning. Anyone who tells you they 'just trained a model' on real data is either lying or working on toy data. Real data starts dirty. The good news — cleaning is mostly mechanical once you know the patterns. Tomorrow we cover the five I run on every dataset.
#NumPy#Pandas#DataScience#Python#100DaysOfCode#DataCleaning