Coming from Pandas?
Introduction
Liken was originally built to provide easy-to-use near deduplication as a single-line bolt-on to the Pandas API.
Warning
Jump to first steps if you need Liken's full suite of tooling to deduplicate Pandas DataFrames.
Near Deduplication
Simply import liken, and pass the deduper as an accessor to your pandas dataframe. Any keyword arguments that usually get passed to the deduper, now simply get passed to drop_duplicates:
import liken as lk # (1)!
import pandas as pd
df = pd.read_csv("...")
df = df.fuzzy.drop_duplicates("address", threshold=0.6) # (2)!
- Liken's Pandas extension is only useable if you actually import
liken! kwargsforfuzzyare delegated todrop_duplicates. This is also true for other dedupers; for example, when using thetfidfdeduper, thengramkwarg would be passed indrop_duplicatestoo i.e.df.tfidf.drop_duplicates("address", threshold=0.6, ngram=3)
Examples
import liken as lk
import pandas as pd
df = pd.DataFrame(
{
"id": [1, 2],
"email": [
"fizzpop@yahoo.com",
"FizzPop@yahoo.com"
],
}
)
deduper = lk.dedupe(df).apply(lk.fuzzy(threshold=0.7))
print("No deduplication:")
print(df.drop_duplicates("email"))
print("\nBut Liken does:")
print(df.fuzzy.drop_duplicates("email", threshold=0.7))
print("\nUse the keep arg:")
print(df.fuzzy.drop_duplicates("email", threshold=0.7, keep="last"))
No deduplication:
id email
0 1 fizzpop@yahoo.com
1 2 FizzPop@yahoo.com
But Liken does:
id email
0 1 fizzpop@yahoo.com
Use the keep arg:
id email
1 2 FizzPop@yahoo.com
You can use multiple columns for any deduper that accepts multiple columns:
import liken as lk
import pandas as pd
df = pd.DataFrame(data=...)
df.knn.drop_duplicates(("height", "width"), threshold=0.6, k=2, keep="last") # (1)!
- A tuple of columns is passed for
knn. Any number ofkwargsbelong toknnare passed todrop_duplicates.
Note
Remember, you must import liken to use these new dataframe accessors!
Limitations
Any deduper that works at a threshold (such as fuzzy, tfidf, lsh, jaccard, and cosine) is allowed. But, predicate dedupers are not supported.