import pandas as pd from snownlp import SnowNLP def sentiment_analysis(text): s = SnowNLP(text) return s.sentiments def do_sentiment_analysis(filename): df = pd.read_csv('barrage.csv') # 对弹幕内容进行情感分析 df['sentiment'] = df['barrage'].apply(sentiment_analysis) print(df.head()) # 保存情感分析结果到CSV文件 df.to_csv('barrage_sentiment.csv', index=False) if __name__ == '__main__': do_sentiment_analysis('barrage.csv')