Pandas将json串转为 DataFrame

path = r"E:\json.txt"
import json
file = open(path,'r')
all_json_data = []
for line in file.readlines():
    json_data = json.loads(line)

df1 = pd.DataFrame(json_data['trainData']['JZ3_YQ'])
df2 = pd.DataFrame(json_data['trainData']['JZ3_YCF'])
df3 = pd.DataFrame(json_data['trainData']['JZ3_ECF'])
df4 = pd.DataFrame(json_data['trainData']['JZ32_YQ'])
df5 = pd.DataFrame(json_data['trainData']['JZ32_YCF'])
df6 = pd.DataFrame(json_data['trainData']['JZ32_ECF'])


dff = pd.concat([df1,df2, df3, df4, df5, df6], axis=1)
dff = dff.iloc[:, [0,1,3,5,7,9,11]]
dff.columns = ['time', 'a', 'b', 'c', 'd', 'e', 'f']
dff

你可能感兴趣的:(python代码,json,数据挖掘,python)