I know this is may be silly, but every research I've done for this question is led to more complex questions, I still can't figure out the basics, I just want to count the frequency of words
Here's my data
id descriptions
1 I love you
2 I love you too
Here's my expected output
id descriptions word count
1 I love you 3
2 I love you too 4
Use:
df['count'] = df['descriptions'].str.count(' ') + 1
Or:
df['count'] = df['descriptions'].str.split().str.len()
Or:
df['count'] = df['descriptions'].str.findall(r'(\w+)').str.len()
print (df)
id descriptions count
0 1 I love you 3
1 2 I love you too 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With