Тональность комментариев
pip install textblob pandas
from textblob import TextBlob
import pandas as pd
# 📌 Пример комментариев
comments = [
"This product is amazing! I love it!",
"Worst experience ever. Do not buy!",
"It's okay, not the best but not the worst.",
"Absolutely fantastic! Highly recommended.",
"Terrible quality, very disappointed."
]
# 📌 Анализ тональности
def get_sentiment(comment):
analysis = TextBlob(comment)
polarity = analysis.sentiment.polarity
if polarity > 0:
return "Positive"
elif polarity < 0:
return "Negative"
else:
return "Neutral"
# 📌 Обрабатываем комментарии
df = pd.DataFrame({"Comment": comments})
df["Sentiment"] = df["Comment"].apply(get_sentiment)
# 📌 Выводим результаты
print(df)