这个报错在VS中怎么解决啊?求助!!!

from itertools import groupby
import pygal
import json

#将数据加载到一个列表中
filename = 'btc_close_2017.json'
with open(filename) as f:
btc_data = json.load(f)

dates = []
months = []
weeks = []
weekdays = []
close = []
#每一天的信息
for btc_dict in btc_data:
dates.append(btc_dict['date'])
months.append(int(btc_dict['month']))
weeks.append(int(btc_dict['week']))
weekdays.append(btc_dict['weekday'])
close.append(int(float(btc_dict['close'])))

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 = [v for _, v in y]
xy_map.append([x, sum(y_list)/len(y_list)])
x_unique, y_mean = [*zip(*xy_map)]
line_chart = pygal.Line()
line_chart.title = title
line_chart.x_labels = x_unique
line_chart.add(y_legend, y_mean)
line_chart.render_to_file(title + '.svg')
return line_chart

idx_month = dates.index('2017-12-01')
line_chart_month = draw_line(months[:idx_month], close[:idx_month], '收盘价月日均值', '月日均值')
line_chart_month

qq_36753831
qq_36753831 求助 VS中写了这段代码 一直报错
大约一年之前 回复
qq_36753831
qq_36753831 TypeError("object of type 'int' has no len()",)
大约一年之前 回复

1个回答

无非是包不完整,或者是csv文件数据不对,参考这个
https://juejin.im/post/5b0d79156fb9a00a277f0bb2
完全按照它的环境和数据试下。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐