这一次用pandas处理csv文件
comments.csv
import pandas as pd
from snownlp import SnowNLPdf = pd.read_csv("C:\\Users\\zhour\\Documents\\comments.csv")#{'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}是个字典
emotions=[]
for txt in df['sentence']:s = SnowNLP(txt)emotions.append(s.sentiments)
df.insert(loc=1, column='emotion', value=emotions) # 在第二列位置插入新列 df.to_csv("C:\\Users\\zhour\\Documents\\commentsTag.csv",index=False, encoding='gbk')
commentsTag.csv