Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply scatter plot and line chart on a dataframe for my bitcoin sentiment analysis?

I want to be able to create a scatter plot and line chart and find out if there is a relationship between the price of Bitcoin and the sentiments of the tweets of the people. I have a column that is Compound, Positive, Neutral, and Negative and I want them to show the relationship between Bitcoin price and the sentiment of the people. Can someone recommend a solution on how to apply various data visualization techniques to show the relationship between Bitcoin sentiments and the price over time? Maybe something like a scatter plot or a line chart. Thank you!

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns

analyzer = SentimentIntensityAnalyzer()
df=pd.read_csv('cleaned_with_price.csv', header = 0)
df2 = df.drop(['Unnamed: 0', 'id', 'fullname', 'url', 'timestamp', 'replies', 'likes', 'retweets'], axis=1)

## removed unnecesarry stuff
tweets_list = df2['text'].tolist()
tweet_df = pd.DataFrame(tweets_list, columns = ['Tweet'])
tweet_df

Which gives this, enter image description here

## add columns for each score in the dataframe

tweet_df.Tweet = tweet_df.Tweet.astype('str')

df2['Compound'] = [analyzer.polarity_scores(twt)['compound'] for twt in tweet_df['Tweet']]
df2['Positive'] = [analyzer.polarity_scores(twt)['pos'] for twt in tweet_df['Tweet']]
df2['Neutral'] = [analyzer.polarity_scores(twt)['neu'] for twt in tweet_df['Tweet']]
df2['Negative'] = [analyzer.polarity_scores(twt)['neg'] for twt in tweet_df['Tweet']]   
df2

Which outputs this: enter image description here

Can someone recommend a solution on how to apply various data visualization techniques to show the relationship between Bitcoin sentiments and the price over time?

like image 227
eizenyamakichi Avatar asked Dec 12 '25 12:12

eizenyamakichi


1 Answers

If I understand your question correctly, try something like this:

plt.scatter(df2['Date'], df2['Compound'])
plt.scatter(df2['Date'], df2['Positive'])
...
plt.show()
like image 193
Alexander Korovin Avatar answered Dec 15 '25 14:12

Alexander Korovin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!