I have a csv document in which each row contains a string of words. For each row, I want to know how many times each words appears in that row, how would I go about this?
Thanks
I have a csv document in which each row contains a string of words. For each row, I want to know how many times each words appears in that row, how would I go about this?
Thanks
Move the row to a list, make it unique and count every object in list,
For converting to list Check this
if result is more than one, print it.
Considered this as list ['a','b','a','c']
z=['a','b','a','c']
u=set(z)
for i in u:
if z.count(i)>1: print i,z.count(i)
Output:
`a 2`
Use collections.Counter
:
from collections import Counter
z = ['a', 'b', 'c', 'd', 'a']
u = Counter(z)
print(u['a']) # 2
print(u['b']) # 1