You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
488 B
20 lines
488 B
2 months ago
|
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')
|