import pandas as pd
import re
from collections import Counter
STOPWORDS = set(['的','了','是','我','也','就','都','很','还','在'])
NEGATIVE = ['贵','挤','吵','乱','低消','黄牛','不安全','退票难','看不见']
POSITIVE = ['氛围','治愈','好听','松弛','震撼','开心','出片','共鸣']
TOUCHPOINTS = {
'购票决策':['票价','黄牛','抢票','退票'],
'到店体验':['拥挤','排队','看不见','音响','安全'],
'消费结算':['酒水','低消','套餐','周边']
}
def clean_text(text):
text = re.sub(r'http\S+|#.*?#|@\S+', ' ', str(text))
text = re.sub(r'[^\u4e00-\u9fa5A-Za-z0-9]+', ' ', text)
return text.strip()
def sentiment_score(text):
return sum(w in text for w in POSITIVE) - sum(w in text for w in NEGATIVE)
def tag_touchpoint(text):
tags = [stage for stage, kws in TOUCHPOINTS.items() if any(k in text for k in kws)]
return '、'.join(tags) if tags else '未识别'
df = pd.read_csv('livehouse_comments.csv')
df['clean'] = df['comment'].map(clean_text)
df = df.drop_duplicates(subset=['clean'])
df['sentiment_score'] = df['clean'].map(sentiment_score)
df['sentiment'] = pd.cut(df['sentiment_score'], [-99,-1,0,99], labels=['negative','neutral','positive'])
df['touchpoint'] = df['clean'].map(tag_touchpoint)
keywords = Counter([w for row in df['clean'] for w in row.split() if w not in STOPWORDS]).most_common(50)
df.to_csv('livehouse_comments_cleaned.csv', index=False)