top_N = 100
words = review_tip['user_tip'].dropna()
words = words.astype(str)
words = words.str.replace('[{}]'.format(string.punctuation), '')
words = words.str.lower().apply(lambda x: ' '.join([word for word in x.split() if word not in (stopwords)]))
# replace '|'-->' ' and drop all stopwords
words = words.str.lower().replace([r'\|', RE_stopwords], [' ', ''], regex=True).str.cat(sep=' ').split()
# generate DF out of Counter
rslt = pd.DataFrame(Counter(words).most_common(top_N),
columns=['Word', 'Frequency']).set_index('Word')
print(rslt)
plt.clf()
# plot
rslt.plot.bar(rot=90, figsize=(16,10), width=0.8)
plt.show()
Frequency
Word
great 17069
food 16381
good 12502
service 11342
place 10841
best 9280
get 7483
love 7042
amazing 5043
try 4945
time 4810
go 4594
dont 4377
正如你所看到的那些单词是单数的,这是我可以使用的东西,但它是否可以像两个可以一起使用的单词一样?
例如获取
不要去(这可能是100次)
而不是分开
不要100
去100
答案 0 :(得分:0)
这会生成二元组,这就是你要找的东西:
bi_grams = zip(words, words[1:])
我生成的元组可以在柜台中使用,但您也可以轻松调整代码以使用' '.join((a, b))
。