如何计算一个单词在一列中的字符串出现在Python中的次数?例如:如何计算单词在一列中出现的次数,python
file|context
----|-------
1 | Hello world
2 | Round and round
我想计算的话发生:
file| context | word_count
----|-----------------|---------------------
1 | Hello world | {'hello':1,'world':1}
2 | Round and round | {'round':2,'and':1}
我一直停留在它了整整一天,并试图用value_counts()和计数器。仍然无法弄清楚。任何帮助?
谢谢!
你是如何尝试使用Counter和value_counts()? –
你正在展示什么样的数据结构?如果您正在讨论解析文本表而不是像pandas'数据框这样的工作,你会得到非常不同的答案。可能会添加适当的标签('string'和'count'在这里非常无用)。 – Blckknght