Edilitics | Data to Decisions

Drop Duplicate Rows

Remove duplicate rows using a single column or a composite key of several columns. Choose to keep the first, last, or no occurrences.

Drop Duplicate Rows removes rows that repeat across one or more selected columns. Select a single column, or select several to form a composite key: a row is only treated as a duplicate if it matches another row on every selected column together, not on any one of them alone. You choose one handling rule for the whole operation: keep the first occurrence, the last, or none at all.

All column types are supported as deduplication keys.


When to Use Drop Duplicate Rows

  • Enforcing a single-column unique key. Customer IDs, order numbers, or transaction codes should appear only once. Drop duplicates on that column before any aggregation or join.
  • Enforcing a composite unique key. A dataset of order line items is often unique on (order_id, product_id) together, not on either column alone. Select both columns as the deduplication key to remove only true duplicate line items, without collapsing an order down to a single row.
  • Cleaning merged or appended datasets. When two datasets are combined, the same record can appear twice. Deduplicate on a unique identifier, single or composite, to collapse them to one.
  • Keeping the latest record per entity. Sort by a timestamp column first, then deduplicate with Keep Last to retain the most recent entry per customer or product.
  • Keeping the earliest record per entity. Deduplicate with Keep First to retain the original registration or first order per customer.
  • Removing all ambiguous rows. Use Keep None when you want to discard any row where a duplicate exists, not just remove the extras.

Sample Dataset

The examples in this doc use the Edilitics sample orders dataset. Download it to follow along in your own workspace.

edilitics_sample_orders.csv

Sample orders dataset for hands-on practice · 500 rows

Download

Relevant columns for Drop Duplicates examples:

Prop

Type


Single-Column and Composite Keys

Select one column and Edilitics checks that column alone for duplicates. Select more than one column and they form a composite key together: a row is only a duplicate if every selected column matches another row's value for that column.

Example dataset of order line items:

order_idproduct_idquantity
ORD-1P-1002
ORD-1P-2001
ORD-2P-1003

Deduplicating on order_id alone would treat every row with the same order_id as a duplicate and collapse the order down to a single line item, losing real data: P-200 would be dropped from ORD-1.

Deduplicating on the composite key order_id + product_id correctly keeps all three rows: no combination repeats. Only a genuinely repeated (order_id, product_id) pair, such as the same product accidentally added twice to the same order, would be removed.


The Three Handling Rules

The handling rule applies once, to the whole deduplication key (single column or composite), not separately per column.

Keeps the first occurrence of each key value (or key combination) and removes all subsequent duplicates.

customer_idorder_daterevenue
C0012024-01-10500
C0012024-03-22800
C0022024-02-14300

After deduplicating on customer_id with Keep First:

customer_idorder_daterevenue
C0012024-01-10500
C0022024-02-14300

The first C001 row (January) is kept. The March row is removed.

Best for: retaining the original or earliest record per entity.

Keeps the last occurrence of each key value (or key combination) and removes all earlier duplicates.

customer_idorder_daterevenue
C0012024-01-10500
C0012024-03-22800
C0022024-02-14300

After deduplicating on customer_id with Keep Last:

customer_idorder_daterevenue
C0012024-03-22800
C0022024-02-14300

The last C001 row (March) is kept. The January row is removed.

Best for: retaining the most recent record per entity. Sort by a date column ascending before running this operation to ensure "last" means "most recent."

Removes all rows whose key value (or key combination) appears more than once. Both the original and the duplicate are dropped.

customer_idorder_daterevenue
C0012024-01-10500
C0012024-03-22800
C0022024-02-14300

After deduplicating on customer_id with Keep None:

customer_idorder_daterevenue
C0022024-02-14300

Both C001 rows are removed because customer_id C001 appeared more than once. C002 is kept because it appeared exactly once.

Best for: strict quality pipelines where any duplicated key is considered invalid and should be excluded entirely.


How to Apply Drop Duplicate Rows

Open the Drop Duplicate Rows operation

In your Transform pipeline, click Add Operation and select Drop Duplicate Rows from the operation list.

Select one or more deduplication key columns

Choose the column whose values will be checked for duplicates. All column types are available.

Click Add Column to add another column to the same key. Selecting more than one column forms a composite key: a row is only a duplicate if it matches another row on every selected column together.

A column selected once is removed from the dropdown for the other key rows, so the same column cannot be added to the key twice.

Choose a handling rule

Select Keep First, Keep Last, or Keep None from the Duplicate Handling Rule dropdown. This one choice applies to the whole operation, whether the key is a single column or several.

  • Keep First: keeps the earliest occurrence, removes the rest.
  • Keep Last: keeps the most recent occurrence, removes the rest.
  • Keep None: removes all rows where the key value, or key combination, appears more than once.

Configure Tie-Break Sort (optional)

Select a sort column and direction under Tie-Break Sort to determine row priority before deduplication runs. For example, select updated_at descending with Keep First to retain the latest record per customer ID without needing a separate sort step earlier in the pipeline.

Remove a key column (optional)

Click the remove icon on any row to remove it from the key. The remove icon only appears when more than one key column is selected.

Save the operation

Click Save & Preview. Edilitics applies the rule across the full deduplication key. A success toast confirms: "Duplicate rows removed. Preview updated with the de-duplicated result."

Verify in the preview

Check the row count and spot-check values in the key column(s) to confirm duplicates were handled as expected.


Before and After

Dataset with duplicate customer_id values:

customer_idorder_daterevenue
C0012024-01-10500
C0012024-03-22800
C0022024-02-14300
C0032024-01-05150
C0032024-04-01420

After deduplicating on customer_id with Keep Last (dataset pre-sorted ascending by order_date):

customer_idorder_daterevenue
C0012024-03-22800
C0022024-02-14300
C0032024-04-01420

5 rows reduced to 3. Most recent order per customer retained.


Code Equivalent

-- Keep Last: use ROW_NUMBER to rank by date, keep rank = 1 after sorting desc
WITH ranked AS (
  SELECT *,
    ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) AS rn
  FROM orders
)
SELECT * EXCLUDE rn
FROM ranked
WHERE rn = 1;

-- Composite key (order_id, product_id): PARTITION BY both columns
WITH ranked AS (
  SELECT *,
    ROW_NUMBER() OVER (PARTITION BY order_id, product_id ORDER BY order_date DESC) AS rn
  FROM order_line_items
)
SELECT * EXCLUDE rn
FROM ranked
WHERE rn = 1;
import polars as pl

# Single-column key, Keep Last occurrence per customer_id
df = df.unique(subset=["customer_id"], keep="last")

# Keep First
df = df.unique(subset=["customer_id"], keep="first")

# Keep None (drop all rows where customer_id appears more than once)
df = df.unique(subset=["customer_id"], keep="none")

# Composite key: a row is a duplicate only if BOTH columns match
df = df.unique(subset=["order_id", "product_id"], keep="first")

After Save & Preview, the pipeline shows a DQ delta badge on this step: green if the table score improved, red if it dropped. See Data Quality Scoring for how scores are calculated.


Operation Reference

Prop

Type


Frequently Asked Questions


Next Steps

Need help? Email support@edilitics.com with your workspace, job ID, and context. We reply within one business day.

Last updated on

On this page