Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import json
  2. import numpy as np
  3. import matplotlib.pylab as plt
  4. import math
  5. from datetime import datetime
  6. import pandas as pd
  7. data = []
  8. with open("bitcoin.json") as f:
  9. for i,j in json.load(f)["bpi"].items():
  10. data.append([datetime.strptime(i,"%Y-%m-%d"), j])
  11. for date, value in data:
  12. pass
  13.  
  14. all_dates=[]
  15. price=[]
  16. dates_2018=[]
  17. price_2018=[]
  18.  
  19. for date,value in data:
  20. all_dates.append(date)
  21. price.append(value)
  22. a=str(date)
  23. if "2018" in a:
  24. dates_2018.append(date)
  25. price_2018.append(value)
  26. if "2019" in a:
  27. break
  28. # print(dates_2018)
  29. # print(price_2018)
  30. plt.plot(dates_2018,price_2018,"b-")
  31. # plt.show()
  32. # plt.savefig("2018.png")
  33. weekly_price=[]
  34. x=0
  35. y=7
  36. # for i in price_2018[x:y]:
  37. # b.append(i)
  38. # weekly_price.append(sum(b[x:y])/7)
  39. # x+=7
  40. # y+=7
  41. # if x==364:
  42. # break
  43. # print(sum(b(0,7)))
  44. # print(weekly_price)
  45. # print(len(weekly_price))
  46. # counter=0
  47. # week=0
  48. # week1=0
  49. # while counter!=364:
  50. # counter+=1
  51. # weekly_price+=price_2018[counter]
  52. # week1=week/7
  53. # if counter%7 == 0:
  54. # weekly_price.append(week)
  55. # print(weekly_price)
  56. # print(len(weekly_price))
  57.  
  58. # store sum every 7 values
  59. weeks=[i for i in range(0,53)]
  60. # weeks=datetime.strptime("%Y"-"%m"-"%d")
  61. while x<364:
  62. weekly_price.append(sum(price_2018[x:y])/7)
  63. x+=7
  64. y+=7
  65.  
  66. # print(price_2018)
  67. weekly_average=[]
  68. for pr in weekly_price:
  69. for i in range(0,7):
  70. weekly_average.append(pr)
  71. weekly_average.append(price_2018[364])
  72. print(weekly_average)
  73.  
  74.  
  75. print(weekly_price)
  76. print(len(weekly_price))
  77. plt.xlabel("Dates2018")
  78. plt.ylabel("Price")
  79. plt.title("WeeklyAverage Red, YearlyPrice Blue")
  80. plt.plot(dates_2018,weekly_average,"r-")
  81. # plt.show()
  82. plt.savefig("weeklyaverageanddailyprice.png")
  83. # print(weeks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement