简体   繁体   English

“TypeError: list indices must be integers or slices, not tuple”——如何解决

[英]“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.

相关问题 如何解决 Python 中的“TypeError:元组索引必须是整数或切片”错误? - How to solve "TypeError: tuple indices must be integers or slices" error in Python? TypeError:列表索引必须是整数或切片,而不是元组? - TypeError: list indices must be integers or slices, not tuple? TypeError:列表索引必须是整数或切片,而不是元组 - TypeError: list indices must be integers or slices, not tuple 如何修复“类型错误:列表索引必须是整数或切片,而不是元组” - How to fix "TypeError: list indices must be integers or slices, not tuple" 如何解决“类型错误:列表索引必须是整数或切片,而不是 str” - How to solve "TypeError: list indices must be integers or slices, not str" 如何解决TypeError:列表索引必须是整数或切片,而不是python中的str - how to solve TypeError: list indices must be integers or slices, not str in python 如何解决 TypeError:列表索引必须是整数或切片,而不是套接字 - How to solve TypeError: list indices must be integers or slices, not sockets 列表类型错误:列表索引必须是整数或切片,而不是元组 - List of lists TypeError: list indices must be integers or slices, not tuple TypeError:列表索引必须是整数或切片,而不是元组列表的元组 - TypeError: list indices must be integers or slices, not tuple for list of tuples 类型错误:列表索引必须是整数或切片,而不是在 python 中使用 sys 导入的元组 - TypeError: list indices must be integers or slices, not tuple with sys import in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM