仅过滤单词而不是标点符号

问题描述

我试图从本质上浏览正面 ('pos') 和负面 ('neg') 列表。这里的问题是下面的脚本也包括空格和标点符号,我不想要那样。我只想从这些列表中提取最常见的 30 个单词。知道如何做到这一点吗?

#for counting frequently occurrence of negative and positive words.

from collections import Counter

count1 = Counter(" ".join(data[data['sentiment']=='pos']["text"]).split()).most_common(30)
data1 = pd.DataFrame.from_dict(count1)
data1 = data1.rename(columns={0: "words of positive",1 : "count"})
count2 = Counter(" ".join(data[data['sentiment']=='neg']["text"]).split()).most_common(30)
data2 = pd.DataFrame.from_dict(count2)
data2 = data2.rename(columns={0: "words of negative",1 : "count_"})

编辑

上面的实现有正确的想法,但是我希望提取具有意义的单词而不是逻辑连接词,例如 (the,and a it that) 以及标点符号

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)