我正在計算我的數據框的一列中的單個詞。它看起來像這樣。實際上,文本是推文。計算熊貓數據框中的單個詞
text
this is some text that I want to count
That's all I wan't
It is unicode text
所以我從其他計算器問題,發現的是,我可以使用以下方法:
Count most frequent 100 words from sentences in Dataframe Pandas
Count distinct words from a Pandas Data Frame
我DF被稱爲結果,這是我的代碼:
from collections import Counter
result2 = Counter(" ".join(result['text'].values.tolist()).split(" ")).items()
result2
我得到了follo翼錯誤:
TypeError Traceback (most recent call last)
<ipython-input-6-2f018a9f912d> in <module>()
1 from collections import Counter
----> 2 result2 = Counter(" ".join(result['text'].values.tolist()).split(" ")).items()
3 result2
TypeError: sequence item 25831: expected str instance, float found
文本的D型爲對象,從我的理解是Unicode文本數據是正確的。
如果您的數據框中存在float值,您想要對它們做什麼?你想數它們嗎? –
由於這些文本應該是所有的推文,我也想數它們。如果此列還包含浮點值,那麼這是否意味着我收集的tweet只是數字? (讓我好奇哪些是浮動) – Lam
是可能的。 –