[英]“TypeError: list indices must be integers or slices, not tuple”- how to solve
I want to convert my big json file(up to 1GB) into csv then print it.My code:我想将我的大 json 文件(最大 1GB)转换为 csv 然后打印它。我的代码:
f = open('C:\\Users\\non_coder\\Desktop\\datasets_fldr\\layer2.json',)
data = json.load(f)
f.close()
df = json_normalize(data['ingredients',])
d_file = df.to_csv('json-to-csv.csv', sep=',', encoding='utf-8')
print(d_file)
Then the error:然后是错误:
<ipython-input-23-4a2ec3b63241> in <module>
5 f.close()
6
7 ---->df = json_normalize(data['ingredients',]) #problem indicates in this line
8 d_file = df.to_csv('json-to-csv.csv', sep=',', encoding='utf-8')
9 print(d_file)
TypeError: list indices must be integers or slices, not tuple.
How should I deal with this我该如何处理
f = open('C:\\Users\\non_coder\\Desktop\\datasets_fldr\\layer2.json',)
data = json.load(f)
f.close()
df = json_normalize(data['ingredients']) # <------- delete the comma here
d_file = df.to_csv('json-to-csv.csv', sep=',', encoding='utf-8')
print(d_file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.