我的数据框如下所示:
ID topics text
1 1 twitter is my favorite social media
2 1 favorite social media
3 2 rt twitter tomorrow
4 3 rt facebook today
5 3 rt twitter
6 4 vote for the best twitter
7 2 twitter tomorrow
8 4 best twitter
我想按主题分组,并使用count矢量器(我真的更喜欢使用countvectorize,因为它允许删除多种语言中的停止词,我可以设置3到4克的范围)来计算最频繁的二元图.在获得最频繁的二元图之后,我想创建一个名为"二元图"的新列,并将每个主题最频繁的二元图分配给该列.
我希望我的输出像这样.
ID topics text biagram
1 1 twitter is my favorite social favorite social
2 1 favorite social media favorite social
3 2 rt twitter tomorrow twitter tomorrow
4 2 twitter tomorrow twitter tomorrow
5 3 rt twitter rt twitter
6 3 rt facebook today rt twitter
7 4 vote for the bes twitter best twitter
8 4 best twitter best twitter
请注意,"主题"列不需要按主题排序.我在写这篇文章的时候是为了形象化.
此代码将在600万行数据上运行,因此需要快速.
使用Pandas 最好的方法是什么?如果事情太复杂,我道歉.