First Steps
Info
If you are a pandas user who wants simple, enhanced, deduplication perhaps the Coming from Pandas? tutorial is sufficient? If not, the full Liken workflow is taught from here onwards (with full support for pandas).
The Liken Workflow
- Construct:
lk.dedupe(df)wraps your DataFrame. Liken detects which backend to use from the DataFrame's type. - Apply:
.apply(...)adds dedupers to a collection. You can apply one deduper, a dict of per-column predicates, or a pipeline. - Execute:
.drop_duplicates()or.canonicalize()executes the applied dedupers, matches records, and returns a new DataFrame.
import liken as lk
deduper = lk.dedupe(df) # construct
deduper = deduper.apply(lk.fuzzy()) # apply
df = deduper.drop_duplicates("address") # execute
Note
After constuction, you may want to profile duplicate rates in your data before continuing with the workflow.
Instantiating
Pass your dataframe to the top-level dedupe function.
Duplicate Rate Profiling
Before choosing a threshold, measure the variance @ threshold for any column. explore reports, for each column you name, the share of records that would be removed under exact matching and under each fuzzy threshold:
| metric | address | |
|---|---|---|
| exact | 0.0 | 0.000000 |
| 0.5 | 0.0 | 0.333333 |
| 0.75 | 0.0 | 0.333333 |
| 0.9 | 0.0 | 0.000000 |
| 0.95 | 0.0 | 0.000000 |
| 0.99 | 0.0 | 0.000000 |
Output: Duplicate rates for the a two-column dataset. Neither address or email has exact matches. But at thresholds 0.5 and 0.75, 1/3 of the emails are duplicates, at higher thresholds, no emails are considered duplicates.
In the above:
- The
exactrow is the exact-matching duplicate rate. It is 0.0 for both columns: all three emails are distinct strings, as are the addresses. - Each numbered row is one fuzzy threshold. The default sweep is 0.5, 0.75, 0.9, 0.95 and 0.99. At 0.5 and 0.75 the two email variants match, so one of three records is a redundant duplicate: a rate of 0.333. At 0.9 they no longer match.
- A rate of 0.333 on 3 records means
drop_duplicateswould remove exactly one record under that threshold.
On larger data, use a sample instead of scanning everything, for a faster exploration. frac takes a fraction where the default of 1.0 uses every row:
By default, each column is profiled with fuzzy. To profile a column with a different threshold deduper, pass a dict instead of a list: keys are column labels, values are single-column threshold dedupers:
Warning
explore runs on the pandas, polars, modin and pyarrow backends. On dask, ray or pyspark, explore is not supported and raises a ValueError.