I have a dataframe column which is a list of strings:
df[\'colors\']
0 [\'blue\',\'green\',\'brown\']
1 []
2 [\'green\
You can use Counter from the collections module:
import pandas as pd
from collections import Counter
from itertools import chain
df = pd.DataFrame({'colors':[['blue','green','brown'],
[],
['green','red','blue'],
['purple'],
['brown']]})
df = pd.Series(Counter(chain(*df.colors)))
print (df)
Output:
blue 2
green 2
brown 2
red 1
purple 1
dtype: int64