I have a pandas dataframe that contains queries and counts for a given time period and I'm hoping to turn this dataframe into a count of unique words. For example, if the dataframe contained the below:
query count
foo bar 10
super 8
foo 4
super foo bar 2
I'm looking to receive the below dataframe. e.g. the word 'foo' appears exactly 16 times within the table.
word count
foo 16
bar 12
super 10
I'm working with the below function, but it hardly seems like the optimal way to do this and it ignores the total count for each row.
def _words(df):
return Counter(re.findall(r'\w+', ' '.join(df['query'])))
Any help will be greatly appreciated.
Thanks in advance!