Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import plotly.plotly as py
- import plotly.graph_objs as go
- import plotly
- plotly.tools.set_credentials_file(username='myusername', api_key='XXXXXXXXXXXX')
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import pandas as pd
- import matplotlib.pyplot as plt
- import matplotlib.patches as mpatches
- import datetime as dt
- import numpy as np
- from datetime import datetime
- df_sentiment = pd.read_csv('user/my path / ......',
- sep=None, engine='python')
- df_sentiment = pd.DataFrame({'sentiment': [np.mean([int(num) for num in d[1:len(d)-1].split(',')]) for d in df_sentiment.sentiment],
- 'date': df_sentiment.date})
- df_sentiment = df_sentiment.reindex(index=df_sentiment.index[::-1])
- df = df_sentiment
- # Create and style traces
- trace0 = go.Scatter(
- x = df.date,
- y = df.sentiment,
- name = 'Bitcoin',
- line = dict(
- color = ('rgb(205, 12, 24)'),
- width = 4)
- )
- df_bitcoin = pd.read_csv('my path/bitcoin ...csv')
- trace1 = go.Scatter(
- x = df.date,
- y = df.price,
- name = 'Bitcoin',
- mode='lines+markers',
- line = dict(
- color = ('rgb(22, 96, 167)'),
- width = 4)
- )
- data = [trace0, trace1]
- # Edit the layout
- layout = dict(title = 'Sentiment Analysis on Social Media',
- xaxis = dict(title = 'June 2018'),
- yaxis = dict(title = 'Sentiment'),
- )
- fig = dict(data=data, layout=layout)
- py.iplot(fig, filename='styled-line')
- 0 2018-06-01 [-1, -1, 0]
- 1 2018-06-02 [0, 1, 0, 0, -1, -1, -1, 1, -1]
- 2 2018-06-03 [-1, 1, 1, 0, 0, -1, -1, -1, 0, 1, 1]
- 3 2018-06-04 [1, 1, 0, 1, 1, 0, 1, -1, 0]
- 4 2018-06-05 [1, 1, 1, -1, 1, -1]
- 5 2018-06-06 [1, 0, 1, -1, -1, 1, 1, 1, 1]
- "Jun 30, 2018","6,391.50","6,208.20","6,518.10","6,195.80","23.86K","2.95%"
- "Jun 29, 2018","6,208.10","5,848.10","6,273.00","5,782.90","33.93K","6.12%"
- "Jun 28, 2018","5,850.00","6,133.10","6,167.70","5,829.90","17.94K","-4.62%"
- "Jun 27, 2018","6,133.09","6,073.50","6,181.40","5,989.00","18.27K","0.90%"
- "Jun 26, 2018","6,078.50","6,250.80","6,273.70","6,050.20","18.83K","-2.69%"
- "Jun 25, 2018","6,246.60","6,146.10","6,334.20","6,082.10","27.91K","1.60%"
Add Comment
Please, Sign In to add comment