30 lines
788 B
Python
30 lines
788 B
Python
|
import pandas as pd
|
||
|
from snownlp import SnowNLP
|
||
|
import matplotlib.pyplot as plt
|
||
|
|
||
|
def load_data(file_path):
|
||
|
try:
|
||
|
df = pd.read_csv(file_path, usecols=['弹幕内容'], engine='python')
|
||
|
return df['弹幕内容'].dropna().astype(str).tolist()
|
||
|
except Exception as e:
|
||
|
print(f"数据加载失败: {str(e)}")
|
||
|
return []
|
||
|
|
||
|
# 示例文件路径
|
||
|
file_path = "hot_data/GMV/BV1ajXMYUE6S/BV1ajXMYUE6S_273_danmaku.csv"
|
||
|
|
||
|
# 执行分析
|
||
|
danmu_texts = load_data(file_path)
|
||
|
|
||
|
emotions = {'positive': 0,
|
||
|
'negative': 0,
|
||
|
'neutral': 0}
|
||
|
|
||
|
for item in danmu_texts:
|
||
|
s = SnowNLP(item)
|
||
|
if s.sentiments > 0.6:
|
||
|
emotions['positive'] += 1
|
||
|
elif s.sentiments < 0.4:
|
||
|
emotions['negative'] += 1
|
||
|
else:
|
||
|
emotions['neutral'] += 1
|