Skip to the workspace
Pebellslearn by building
Data Cleanup  ›  Lesson

Removing Duplicates

Removing Duplicates 12 minA duplicate is a row that records the same real event twice, so decide which columns identify an event before deleting anything.

data analyst / Removing Duplicates

Explore each scene at your own pace.

01 · The rule

The rule

Removing Duplicates

The till lost its connection for ten minutes on 3 June and re-sent its orders when it came back. Now some orders appear twice, and June's revenue looks better than it really was. Duplicates inflate every total and count, but deleting the wrong row is just as bad. The skill is deciding what "the same" means.

The rule

Decide what makes a row unique, then keep one per key.

There are two kinds of duplicate:

  • Exact duplicates: every column is identical, including the ID. These are almost always copying errors, like the till re-sending.
  • Near duplicates: the same real event recorded with small differences, such as a different ID, a trailing space, or Asha Rao versus asha rao.

And one important non-duplicate: two genuine events that look alike. Asha buying two croissants on Monday and again on Wednesday is two orders, even if the item, quantity and amount match.

The fix is to choose the key: the columns that together identify one real event. For orders, that is normally order_id. For a customer list without IDs, it might be name plus phone number, after cleaning both.

order_id order_date customer item_code qty amount
1004 2025-06-03 Asha Rao B02 2 220
1004 2025-06-03 Asha Rao B02 2 220
1005 2025-06-04 Dev Menon C01 1 120
1008 2025-06-05 Dev Menon C01 1 120

The two 1004 rows share a key: keep one. Orders 1005 and 1008 have different IDs and dates: both are real.

In Excel, Data → Remove Duplicates lets you tick which columns form the key. In SQL, SELECT DISTINCT or GROUP BY the key does the same job.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.