我正在对一个食品评论数据进行情感分析,并注意到如果评论有一个'!‘在这篇文章中,评论往往是积极的。因此,我计划根据评论来预测评论的评分,如果它涉及“!”收视率会更高。我为积极的评论生成了一个词云,但它不包含标点符号。有没有办法显示“!”或者打印出正面评论中的感叹号计数?
发布于 2019-05-13 23:43:51
假设你有一个数据帧,如下所示:
df = pd.DataFrame({'sentiment': ['positive', 'positive', 'negative', 'positive'], 'sentence': ['This is cool!', 'this is ok', 'not very cool', '!!!']})
sentiment sentence
0 positive This is cool!
1 positive this is ok
2 negative not very cool
3 positive !!!您可能想要对正值进行切片,然后计算!的出现次数(据我所知):
df[df['sentiment'] == 'positive'].sentence.str.count('!').sum()结果:
4
https://stackoverflow.com/questions/56115615
复制相似问题