The import json
The import math
The import pygal
# to load data into a list
Filename='btc_close_2018. Json'
With the open (filename) as f:
btc_data=https://bbs.csdn.net/topics/json.load (f)
# to create five list, storage date and the closing price
Dates=[]
Up=[]
Weekes=[]
Weekdays=[]
The close=[]
Every day # traversal information
For btc_dict btc_data in:
Dates. Append (btc_dict [' date '])
Have append (int (btc_dict [' month ']))
Weekes. Append (int (btc_dict [' week ']))
Weekdays. Append (btc_dict [' weekday '])
Close. Append (int (float (btc_dict [' close '])))
The from itertools import groupby
Def draw_line (x_data y_data, title, y_legend) :
Xy_map=[]
For x, y in groupby (sorted (zip (x_data y_data)), key=lambda _ : _ [0]) :
Y_list=y] in [v for _, v
Xy_map. Append ([x, the sum (y_list)/len (y_list)])
X_unique, y_mean=[* zip (* xy_map)]
Line_chart=pygal. Line ()
Line_chart=title
Line_chart. X_labels=x_unique
Line_chart. Add (y_legend y_mean)
Line_chart. Render_to_file (title + 'SVG')
Return line_chart
# month closing day average line chart
Idx_month=dates. The index (' 2017-12-01 ')
Line_chart_month=draw_line (up [: idx_month], close [: idx_month],
'average monthly closing day', 'month day average')
line_chart_month
CodePudding user response:
In this line of code: line_chart x_labels=x_uniqueIs your x_unique plastic tuple
The plastic tuples into type String list
Then assigned to line_chart. X_labels was no problem ~
Line_chart. X_labels=STR (x_unique)
CodePudding user response:
AttributeError: 'STR' object has no attribute 'astype'