Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python fuzzy match grouped by category

I am trying to clean data using fuzzy match. The df like:

category description
1        almnd
1        almond
2        choc
2        choco

I want to have all similar descriptions to be same one under same category like that:

category description
1        almnd
1        almnd
2        choc
2        choc
like image 913
Python noob Avatar asked Jul 24 '26 20:07

Python noob


1 Answers

Convert your dataframe to a dictionary, and remap.

dico = dict(df.to_dict('split')['data'])
df['description'] = pd["category"].map(dico)

If your dataframe actually has more than these two columns check the accepted answer on dictionary extraction.

dataframe to dict such that one column is the key and the other is the value

like image 114
Serge Avatar answered Jul 26 '26 11:07

Serge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!