# -*- coding:utf-8 -*-
import pandas as pd
import re
import json
import ast
from copy import deepcopy
import os
import numpy as np
import warnings
import sys
warnings.filterwarnings("ignore")
def flatten_json(y):
out = [y]
def flatten(x, result, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], result, name + a + '_')
elif type(x) is list:
result[str(name[:-1])] = x
else:
result[str(name[:-1])] = str(x)
def find_list_key(x):
for k in x:
if type(x[k]) is list:
return k
done = False
while not done:
done = True
for i in range(len(out)):
row = out[i]
result = {}
flatten(row, result)
out[i] = result
for i in reversed(range(len(out))):
row = out[i]
list_key = find_list_ke
json转二维表 python
于 2022-07-05 15:18:33 首次发布
本文介绍了如何使用Python解析JSON数据并转换成二维表格格式,适用于数据分析师和开发者进行数据分析和处理。通过Python的json模块,可以轻松地将JSON对象转换为列表和字典,进一步构造为表格结构。
摘要由CSDN通过智能技术生成