lady是什么意思
⽤python对字符串分词,并计算词数# -*- coding: utf-8 -*-
"""
Created on Tue Mar 24 11:29:53 2020
@author: weisssunvolans
"""
initialize是什么意思
import jieba
import csv
import pandas as pd
jieba.load_urdict(r"D:\Python\")
#加载⽤户词典
input_path = r'D:\Python\data\评论.xlsx'
#原始数据路径
outpath = r'D:\Python\data\评论-词数.csv'
#输出数据路径
results =[]
#将结果保存在results列表中,写⼊csv⽂件
raw_data = pd.read_excel(input_path, encoding ='utf-8')
#读取原始数据
for comment in t.astype(str):tend
#读取原始数据中的⽂本列,并将其转换为字符串格式
#否则jieba会报错
cut_words=[]
result =[]
特色英语培训#print(comment)
g_list = jieba.cut(comment,cut_all=Fal)
survivor#调⽤jieba分词
for i in g_list:
cut_words.append(i)
issue是什么意思#将分词结果保存为列表
#print(cut_words)
#print(len(cut_words))
#word_freq.append(len(cut_words))cathy什么意思
result.append(comment)
soundhound是什么
think greatresult.append(cut_words)
result.append(len(cut_words))
#将原始评论、分词结果、词数保存在列表result中
results.append(result)
#将所有result保存在列表results中
#print(results)
with open(outpath,'w', newline='',encoding='gbk')as f:
writer = csv.writer(f)
for result in results:
writer.writerow(result)
#将结果写⼊csv⽂件,每个result是⼀⾏