I've got a dataframe and want to loop through all cells within column c2 and count how many times each entire string appears in another column c1, if it exists. Then print the results.
Example df:
id c1 c2
0 luke skywalker han solo
1 leia organa r2d2
2 darth vader finn
3 han solo the emporer
4 han solo c3po
5 finn leia organa
6 r2d2 darth vader
Example printed result:
han solo 2
r2d2 1
finn 1
the emporer 0
c3po 0
leia organa 1
darth vader 1
I'm using Jupyter notebook with python and pandas. Thanks!
c2which changes some of the solutions below as indicated by @wen.