Feb-15-2019, 09:10 AM
Thank you for your answer.
I selected the relevant column of the dataframe with:
where x is:
and pass it to your suggested function:
but I got:
Same thing when I applied:
I selected the relevant column of the dataframe with:
x = df['field']
where x is:
x
Out[27]:
0 about me:<br />\n<br />\ni would love to think...
1 i am a chef: this is what that means.<br />\n1...
2 i'm not ashamed of much, but writing public te...
3 i work in a library and go to school. . . read...
4 hey how's it going? currently vague on the pro...
5 i'm an australian living in san francisco, but...
and pass it to your suggested function:
avg_words_len_in_str = lambda s: [len(k) / v for k,v in Counter(s.lower().split()).items()]
avg_words_len_in_str(x)[/icode]
but I got:
avg_words_len_in_str(x)
Traceback (most recent call last):
File "<ipython-input-28-425c839e1d1d>", line 1, in <module>
avg_words_len_in_str(x)
File "<ipython-input-21-78c2dd2340ad>", line 1, in <lambda>
avg_words_len_in_str = lambda s: [len(k) / v for k,v in Counter(s.lower().split()).items()]
`
File "~/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 5057, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'lower'
Same thing when I applied:
count_spec_words = lambda s, specific: [v for k, v in Counter(s.lower().split()).items() if k in specific]
count_spec_words(x, ("I", ))
count_spec_words(x, ("i",))
count_spec_words(x, ("i"))