Skip to content

Guides

How to remove duplicates in Excel, Google Sheets and Python

Every reliable way to find and remove duplicate rows, which copy each method keeps, and why some duplicates survive even after you've "removed" them.

By Ketan ·

Watch the 2-minute video · open on YouTube

Duplicate rows creep in whenever data is copied, merged or exported more than once. Three sign-up forms feeding one list, a report run twice, a VLOOKUP that matched the same row again. They inflate totals and send the same customer the same email twice.

In my work, duplicates are the most common reason two reports that should agree don’t. Before I trust any total, I check the key column for repeats.

Removing them takes seconds once you know which method fits. The tricky part is deciding what counts as a duplicate, and this guide starts there.

First, decide what “duplicate” means

There are two very different questions:

  1. Is the whole row repeated? Every column is identical. Usually caused by importing the same file twice.
  2. Is the same thing listed twice? The same email, order ID or customer appears in more than one row, even if other columns differ, such as an old address in one row and a new one in another.

For the second kind, you also need to pick which row to keep: the first one, the last one (often the most recent), or neither, if you want to see the problem rows on their own.

Keep that decision in mind; every method below asks you for it in some form.

The quick way: in your browser

The Remove duplicates tool handles both kinds. Drop in a CSV or Excel file, untick the columns that shouldn’t be compared, and choose whether to keep the first copy, the last, or none. It also gives you a separate file of the removed rows, so you can check what went. The file is processed on your computer and never uploaded.

In Excel

Remove Duplicates button

  1. Click anywhere in your data.
  2. Go to Data → Remove Duplicates (in the Data Tools group).
  3. Tick the columns that define a duplicate. Untick everything except Email to keep one row per email address.
  4. Click OK. Excel tells you how many rows it removed.

Three things to know:

  • It keeps the first copy and deletes the rest. To keep the latest row instead, sort the data newest-first before you start.
  • It ignores upper and lower case. ASHA@MAIL.COM and asha@mail.com count as the same, which is usually what you want for emails.
  • It doesn’t ignore spaces. Pune and Pune (with a trailing space) are different to Excel. Clean those first with =TRIM(A2) in a helper column.

The deletion happens in place, with no list of what was removed. Copy the sheet first if you might need to check.

UNIQUE function (Excel 365 and 2021)

To leave the original data alone and build a clean copy next to it:

=UNIQUE(A1:D500)

The result spills into as many rows as needed and updates when the source changes. =UNIQUE(A2:A500) gives a list of distinct values from one column.

Find duplicates without deleting them

To see duplicates before removing anything, select the column and use Home → Conditional Formatting → Highlight Cells Rules → Duplicate Values.

To flag every copy after the first, add a helper column with:

=COUNTIF($B$2:B2, B2) > 1

It shows TRUE on the second, third and later appearances of each value. Filter on TRUE to review them, and delete them if you’re happy.

In Google Sheets

  1. Select the data, including the header row.
  2. Go to Data → Data cleanup → Remove duplicates.
  3. Tick Data has header row, choose the columns to compare, and click Remove duplicates.

Sheets also has =UNIQUE(A1:D500), which works like Excel’s version. Before you remove anything, Data → Data cleanup → Trim whitespace gets rid of the stray spaces that make near-identical rows look different.

In Python (pandas)

import pandas as pd

df = pd.read_csv("contacts.csv")

# Whole-row duplicates
df = df.drop_duplicates()

# One row per email, keeping the most recent
df = df.sort_values("updated_at").drop_duplicates(subset=["email"], keep="last")

df.to_csv("contacts_clean.csv", index=False)

keep takes "first", "last" or False (drop every copy). Unlike Excel, pandas is case-sensitive and space-sensitive. Normalise the key first if that matters:

key = df["email"].str.strip().str.lower()
df = df.loc[~key.duplicated()]

To look at the duplicates instead of dropping them: df[df.duplicated(subset=["email"], keep=False)].

In SQL

SELECT DISTINCT * returns each identical row once. To keep one row per key, use a window function:

SELECT *
FROM (
  SELECT *,
         ROW_NUMBER() OVER (PARTITION BY LOWER(TRIM(email)) ORDER BY updated_at DESC) AS rn
  FROM contacts
) t
WHERE rn = 1;

This keeps the newest row per email and works in PostgreSQL, MySQL 8+, SQL Server, BigQuery, Snowflake and DuckDB.

Why some duplicates survive

From experience: when someone says “remove duplicates didn’t work”, it’s nearly always trailing spaces or numbers stored as text. I check those two before anything else.

If you’ve removed duplicates and still see repeats, the rows differ in a way you can’t easily see:

  • Trailing or double spaces. Asha Rao vs Asha Rao vs Asha Rao. Trim first.
  • Upper and lower case, in tools that are case-sensitive (pandas, SQL, and most scripts).
  • Numbers stored as text. 1001 as a number and '1001 as text don’t match. In Excel, look for the small green triangle in the cell corner.
  • Invisible characters, such as non-breaking spaces copied from web pages. =CODE(RIGHT(A2,1)) returning 160 gives this one away.
  • Dates in different formats. 04/01/2026 and 2026-01-04 are the same day, but not the same text.

The Ignore upper/lower case and Ignore extra spaces options in the online tool deal with the first two. For the rest, fix the column in the source file and run it again.