我在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
除了@Joran的解决方案之外,还可以对大量文本/行使用
series.value_counts
从基准测试中可以发现,
series.value_counts
似乎比Counter
方法快两倍(2倍)电影评论数据集有3000行,总计40万个字符和7万个单词。
我很肯定会给你想要的(在调用most_common之前,你可能需要从计数器结果中删除一些非单词)
相关问题 更多 >
编程相关推荐