lundi 8 avril 2019

Count word frequency in tokenized word - with else if logic

I am trying to count the word frequency is a list in a dataframe.

data = {'H':[['the', 'brown', 'fox'], ['the', 'weather', 'is'],['she', 'sells', 'sea']], 'marks':['a', 'b', 'c']} 
df = pd.DataFrame(data)   

I want to separate the word counts based when marks is a,b,c freq = {} def count_freq(word): for w in word: if w in list(freq.keys()): freq[w] += 1 else: freq[w] = 1

df.H.apply(count_freq)

then I tried this but I am messing up

df['marks'] = z.apply(lambda row: 0 if row['marks'] in ("a")
             else if row['marks'] in ("b")
             else row['marks'] in ("c")

Aucun commentaire:

Enregistrer un commentaire