I have a somewhat large dataframe, formatted something like this:
colA colB
1 c, d
2 d, e, f
3 e, d, a
I want to get a dictionary that counts instances of unique values in colB, like:
a: 1
c: 1
d: 3
e: 2
f: 1
My naive solution would be to iterate over every row of colB, split that, then use a Counter
: my_counter[current_colB_object] += 1
.
However, this answer strongly discourages iterating over dataframes, especially (like in my case) large ones.
What would be the preferred way of doing this?