Menu

Duplicates, Inconsistent Labels, and Data Types

Lesson 3: Duplicates, Inconsistent Labels, and Data Types

Why consistency matters

The same category recorded differently is counted as separate groups:

Raw value

Problem

Standardised

"Chennai"–Chennai
"chennai"LowercaseChennai
"Chennai "Trailing spaceChennai
"CHENNAI"UppercaseChennai
"Madras"Old nameChennai (via a mapping table)

Without cleaning, a "revenue by city" report would show five rows for one city.

Duplicates

Type

Example

Error?

Exact duplicateIdentical row appears twiceUsually an error (e.g., double import)
Repeated customer ID in an orders tableA customer placed 5 ordersNot an error
Repeated order ID in a line-item tableOne order with 3 productsNot an error
Repeated order ID in an order-level tableSame order recorded twiceLikely an error
Near-duplicateSame person, slightly different spellingNeeds investigation

Always define what a duplicate means for the table's unit of analysis (grain).

df.duplicated().sum() # exact duplicates
df.duplicated(subset=['order_id']).sum() # duplicate keys
df[df.duplicated(subset=['order_id'], keep=False)] # view all copies

Standardisation

Task

Example

Trim whitespace' South ' → 'South'
Consistent case'SOUTH' → 'South'
Map known variants{'TN': 'Tamil Nadu', 'T.N.': 'Tamil Nadu'}
Parse dates explicitlypd.to_datetime(col, format='%d-%m-%Y')
Unify unitsConvert grams to kilograms
Consistent currencyConvert all values to INR with a documented rate
Fix typesPhone numbers and IDs as text, amounts as numbers
  • Specify date formats explicitly. 03/04/2026 means 3 April in India but 4 March in the US.
  • Preserve original values in a separate column when the transformation could change interpretation or an audit trail is needed.

Example

  • Before removing duplicate order IDs, check the table's grain:
    • One row per order → repeated IDs may be errors.
    • One row per item → repeated IDs are expected.
  • Removing repeated order IDs from a line-item table would delete valid items and undercount revenue.

Key takeaways

  • A cleaning rule must fit the data's structure and business meaning.
  • Count affected rows and validate totals after each important transformation.

Try it: Write a cleaning plan for a table containing inconsistent region names, duplicate-looking order IDs, and dates stored in mixed formats.


Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details