你这个json是嵌套的结构,要先设计下你打算怎么在excel中展示这些数据的(毕竟excel是行列的二维结构)
import pandas as pd
'''打算递归提取'''
def recursive_items(dictionary):
for key, value in dictionary.items():
if isinstance(value,dict):
yield (key, value)
yield from recursive_items(value)
else:
yield (key, value)
dic = {"bc":{"b":2,"c":3},"a":1}#到时候替换成你的
ls = []
insert_dict =dict()
for key, value in recursive_items(dic):
if not isinstance(value,dict):
insert_dict[key] = value
ls.append(insert_dict)
print(ls)
'''打算递归提取'''
#导出表格
writer = pd.ExcelWriter(f"你导出表名称.xlsx")
new_list_3 = [list(insert_dict.values()) for info_dict in ls]
df = pd.DataFrame(new_list_3, columns=list(ls[0].keys()))
df.to_excel(writer, index=False, engine='xlsxwriter')
writer.save()
有Python库文档没?
– kouf 2年前1、没看懂想要啥,需求不明确;2、给数据样例不要用截图的形式,截图不方便操作
– 看破空城观星 2年前