Guest User

Untitled

a guest
Oct 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import plotly.plotly as py
  2. import plotly.graph_objs as go
  3. import plotly
  4. plotly.tools.set_credentials_file(username='myusername', api_key='XXXXXXXXXXXX')
  5. #!/usr/bin/env python
  6. # -*- coding: utf-8 -*-
  7. import pandas as pd
  8. import matplotlib.pyplot as plt
  9. import matplotlib.patches as mpatches
  10. import datetime as dt
  11. import numpy as np
  12. from datetime import datetime
  13.  
  14.  
  15. df_sentiment = pd.read_csv('user/my path / ......',
  16. sep=None, engine='python')
  17. df_sentiment = pd.DataFrame({'sentiment': [np.mean([int(num) for num in d[1:len(d)-1].split(',')]) for d in df_sentiment.sentiment],
  18. 'date': df_sentiment.date})
  19.  
  20. df_sentiment = df_sentiment.reindex(index=df_sentiment.index[::-1])
  21. df = df_sentiment
  22.  
  23. # Create and style traces
  24. trace0 = go.Scatter(
  25. x = df.date,
  26. y = df.sentiment,
  27. name = 'Bitcoin',
  28. line = dict(
  29. color = ('rgb(205, 12, 24)'),
  30. width = 4)
  31. )
  32.  
  33. df_bitcoin = pd.read_csv('my path/bitcoin ...csv')
  34. trace1 = go.Scatter(
  35. x = df.date,
  36. y = df.price,
  37. name = 'Bitcoin',
  38. mode='lines+markers',
  39. line = dict(
  40. color = ('rgb(22, 96, 167)'),
  41. width = 4)
  42. )
  43.  
  44. data = [trace0, trace1]
  45.  
  46. # Edit the layout
  47. layout = dict(title = 'Sentiment Analysis on Social Media',
  48. xaxis = dict(title = 'June 2018'),
  49. yaxis = dict(title = 'Sentiment'),
  50. )
  51.  
  52. fig = dict(data=data, layout=layout)
  53. py.iplot(fig, filename='styled-line')
  54.  
  55. 0 2018-06-01 [-1, -1, 0]
  56. 1 2018-06-02 [0, 1, 0, 0, -1, -1, -1, 1, -1]
  57. 2 2018-06-03 [-1, 1, 1, 0, 0, -1, -1, -1, 0, 1, 1]
  58. 3 2018-06-04 [1, 1, 0, 1, 1, 0, 1, -1, 0]
  59. 4 2018-06-05 [1, 1, 1, -1, 1, -1]
  60. 5 2018-06-06 [1, 0, 1, -1, -1, 1, 1, 1, 1]
  61.  
  62. "Jun 30, 2018","6,391.50","6,208.20","6,518.10","6,195.80","23.86K","2.95%"
  63. "Jun 29, 2018","6,208.10","5,848.10","6,273.00","5,782.90","33.93K","6.12%"
  64. "Jun 28, 2018","5,850.00","6,133.10","6,167.70","5,829.90","17.94K","-4.62%"
  65. "Jun 27, 2018","6,133.09","6,073.50","6,181.40","5,989.00","18.27K","0.90%"
  66. "Jun 26, 2018","6,078.50","6,250.80","6,273.70","6,050.20","18.83K","-2.69%"
  67. "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