前言
本文为小丫用python尝试探索影响手机评论的因素,使用的python库有jieba、wordcloud、numpy、pandas、matplotlib。此外还需要导入stopwords中文库,这个网上有很多分享的。
数据背景
本次使用的数据为清洗后的csv文件,数据分为评论得分和评论内容两列,但是由于用excel反复打开,兼容问题导致最后数据合并为一列了,所以后面代码就基本合并后的数据进行的。
1.读取数据
line = pd.read_csv('C:./mobilephone_c.csv',usecols=[0])
stopwords = pd.read_csv('C:./stopwords12.csv',usecols=[0])
2.剔除stopword以及构建关键词-评论分数 的dataframe
def creat_key_words_and_score_dataframe(line,stopwords):
comment_score = []
key_words=[]
for index, row in line.iterrows():
for comment_line in row:
score= comment_line[0]
comment_cut = jieba.lcut(comment_line[2:]) #jieba分词器进行分词
for key_word in comment_cut:
if key_word not in stopwords.stopword.values and