我在Pandas数据帧的一栏中进行了文本评论,我想用频率计数计算N个最频繁的单词(在整个列中 - 不在单个单元格中) . 一种方法是使用计数器计数单词,通过遍历每一行 . 还有更好的选择吗?
代表性数据 .
0 a heartening tale of small victories and endu
1 no sophomore slump for director sam mendes w
2 if you are an actor who can relate to the sea
3 it's this memory-as-identity obviation that g
4 boyd's screenplay ( co-written with guardian
2 回答
我很确定会给你你想要的东西(在调用most_common之前你可能需要从计数器结果中删除一些非单词)
除了@Joran的解决方案,您还可以使用
series.value_counts
来处理大量文本/行您可以从基准测试中发现
series.value_counts
似乎比Counter
方法快两倍(2X)对于3000行的电影评论数据集,总计400K字符和70k字 .