sentiment / sentiment.py
erfanweb's picture
Create sentiment.py
2f0b408 verified
Raw History Blame Contribute Delete
861 Bytes
import pandas as pd
from transformers import pipeline
data = {
"timestamp": [
"2024-01-01 00:00:00", "2024-01-01 01:00:00", "2024-01-01 02:00:00", "2024-01-01 03:00:00", "2024-01-01 04:00:00",
"2024-01-01 05:00:00", "2024-01-01 06:00:00", "2024-01-01 07:00:00", "2024-01-01 08:00:00", "2024-01-01 09:00:00"
],
"text": [
"Bitcoin is breaking resistance!", "Market looks weak today.", "Sideways action continues.", "ETH momentum is strong.", "Huge sell-off incoming?",
"Altcoins showing strong gains.", "Bearish trend might continue.", "Volume has been decreasing lately.", "Bitcoin hitting new all-time highs.", "Crypto market showing signs of recovery."
]
}
df = pd.DataFrame(data)
classifier = pipeline('sentiment-analysis')
df['sentiment'] = df['text'].apply(lambda x: classifier(x)[0]['label'])
print(df)