【发布时间】:2017-10-24 20:00:58
【问题描述】:
我有一个我想在下面计算的“单词”列表
word_list = ['one','two','three']
我在 pandas 数据框中有一列,下面有文字。
TEXT | USER | ID
-------------------------------------------|---------|------
"Perhaps she'll be the one for me." | User 1 | 100
"Is it two or one?" | User 1 | 100
"Mayhaps it be three afterall..." | User 2 | 150
"Three times and it's a charm." | User 2 | 150
"One fish, two fish, red fish, blue fish." | User 2 | 150
"There's only one cat in the hat." | User 3 | 200
"One does not simply code into pandas." | User 3 | 200
"Two nights later..." | User 1 | 100
"Quoth the Raven... nevermore." | User 2 | 150
我想要的输出如下所示,我想使用“TEXT”列中的数据计算与 word_list 中的任何单词相关的文本的唯一用户数。在计算了唯一用户之后,我还想计算与每条推文相关的关注者总和,与单词的唯一用户数相关联。
Word | Unique User Count | ID Sum
one | 3 | 450
two | 2 | 250
three| 1 | 150
有没有办法在 Python 2.7 中做到这一点?
【问题讨论】:
标签: python python-2.7 pandas