【发布时间】:2017-09-15 03:52:37
【问题描述】:
如何用 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。还是想不通。有什么帮助吗?
谢谢!
【问题讨论】:
-
您是如何尝试使用 Counter 和 value_counts() 的?
-
你展示了什么样的数据结构?如果您正在讨论解析文本表与处理
pandas数据框之类的东西,您会得到非常不同的答案。添加适当的标签,也许(string和count在这里毫无用处)。