I currently have a dataframe like this:
column_1: column_2: column_3:
pizza beer nice, excellent, good
pasta beer good, nice, great
pizza wine great, nice
fish coffee ok
I am trying to get the top-3 words that occur in column_3 and store them into a dictionary.
My expected output:
{ 'nice': 3,
'good': 2,
'great':2 }
What is the best way to do this? Or is it even possible?
Any help is much appreciated.
Using get_dummies
+ nlargest
d=df['column_3:'].str.get_dummies(',').sum().nlargest(3).to_dict()
d
Out[225]: {'good': 2, 'great': 2, 'nice': 3}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With