Field notes on data types. Short version: most “data quality” tickets that reach me are really type mistakes. Opinion first, evidence after. If a column is an identifier, it is text. Always. Even if every character is a digit.
The PIN code that became a four-digit number
Indian PIN codes have six digits. Some begin with zero? Actually, none do in current use, since the first digit is the postal region and runs from 1 to 8. So PIN codes are safer than most. The problem shows up with other codes. Employee IDs like 00457. Branch codes like 0042. GST state codes like 07 for Delhi and 09 for Uttar Pradesh. Mobile numbers stored without the country code. Open such a file in a spreadsheet, let it guess the type, save it, and the leading zeros are gone for good. 00457 becomes 457, and now it will not match the 00457 in the HR system.
The rule of thumb is simple. Ask whether arithmetic on the value makes sense. You can add two order amounts. You cannot meaningfully add two account numbers, and nobody wants the average PIN code. If arithmetic is meaningless, store it as text. That one test removes most of the damage.
Big numbers and scientific notation
A sixteen-digit card-style identifier or a long transaction reference opened in a spreadsheet gets displayed in scientific notation, and spreadsheets generally keep only about fifteen significant digits for a number. Digits after that are replaced by zeros. Two different references can become the same one. I have an opinion on this and it is not a polite one: never let a spreadsheet touch a long identifier you intend to join on. Import the file as text for those columns, or work in a tool that lets you declare the type up front.
Dates: the format is not the type
A value that reads 03/04/2025 is a date in a real database column and just a string in many CSV files. If it is a string, sorting is alphabetical, so 01/12/2024 comes before 02/01/2024 even though it is eleven months later. Worse, nobody can tell whether it means 3 April or 4 March. Indian systems usually write day first and American tools often assume month first. A file that mixes both after being passed between teams will parse without error and give wrong months.
My practice, which you may disagree with: convert dates to an unambiguous year-month-day form at the first step of any pipeline, and keep a separate check that no parsed date falls outside the plausible range. A date of 2025-04-03 cannot be misread, and it sorts correctly even as text.
Time zones are a related trap. A timestamp with no zone attached is ambiguous. A sale at 11:30 pm IST is already the next morning in some systems that store UTC, so daily totals shift. Decide on one stored zone, write it in the column description, and convert only when displaying.
Numbers that are really text
The reverse problem is just as common. Amounts arrive as “₹1,24,500”, with the rupee sign and Indian digit grouping, or as “12.5%” with the percent sign. Until you strip those and convert, the column cannot be summed. Be careful with the commas: stripping them is safe for lakh-style grouping, but if some regions export with a comma as the decimal separator, as parts of Europe do, removing it would change the value by a factor of a hundred or a thousand. Check a sample before running a blanket replacement.
Also watch for numbers whose unit changes. A column named amount may be in rupees for one source and in paise for another, or in lakhs in a finance extract. The type is fine here, the meaning is not. A quick comparison of medians across sources catches a factor of a hundred immediately.
Booleans and flags
Flags come as Y/N, 1/0, true/false, “Yes”, and sometimes blank for “no”. Pick a single representation. And decide what blank means: is it false, or unknown? Those are different things. If 30% of customers have a blank is_married, calling them all “not married” produces a number that sounds plausible and is wrong.
What I actually do
- Declare types explicitly when loading. Do not let the tool infer them from the first hundred rows.
- Treat identifiers as text and compare their lengths. If most codes have five characters and a few have four, the short ones lost a zero.
- Parse dates once, early, into one standard form.
- Write units in column names or descriptions.
- Count the rows that fail conversion and look at them. Do not silently drop them.
The last item matters most. Conversion failures are not noise to be discarded. They are the data telling you which assumption about the source is wrong.
Figures and names in the examples are illustrative.
Leave a Reply