正如標(biāo)題所示,我陷入了一種需要將數(shù)據(jù)幀的一行分解為多行的情況。數(shù)據(jù)框的當(dāng)前狀態(tài):import pandas as pdop_d = {'A': [['NULL', 'NULL','NULL','NULL','NULL']], 'V':[[{'2016': '488.386000'},{'2017': '469.508000'}, {'2018': '445.510000'},{'2019': '579.299000'}, {'2020': '493.786000'}]], 'Q':[[{'2016': '488.386000'},{'2017': '469.508000'}, {'2018': '445.510000'},{'2019': '579.299000'}, {'2020': '493.786000'}]], 'Z': [['NULL', 'NULL','NULL','NULL','NULL']]}df = pd.DataFrame(op_d)數(shù)據(jù)框的期望狀態(tài):op_d2 = {'Date':[2016,2017,2018,2019,2020],'A': ['NULL', 'NULL','NULL','NULL','NULL'], 'V':[488.386000,469.508000,445.510000,579.299000,493.786000], 'Q':[488.386000,469.508000,445.510000,579.299000,493.786000], 'Z': ['NULL', 'NULL','NULL','NULL','NULL']}result_df = pd.DataFrame(op_d2)result_df我所做的是將字典的鍵放入單獨(dú)的“日期”列中,并保持列的值不變。無論它是 NULL,它都將保持原樣。所有列都會(huì)有類似的字典。即相同的日期范圍。我收到 json 格式的原始響應(yīng),將其轉(zhuǎn)換為數(shù)據(jù)幀以執(zhí)行一些計(jì)算。我將不勝感激任何幫助。原始 json 響應(yīng): { 'Prop1': '', 'Prop2': ['Somedata', 'SomeData2'], 'Prop3': 5, 'Prop4': '', 'StartDate': '', 'Function': 'ABC', 'Identifier': 'ID001', 'Col2': 2, 'Prop5': 'XYZ', 'Frequency': '', 'Limit': '', 'Rows': [{'Row': ['136.731000', '2016']}, {'Row': ['135.331000', '2017']}, {'Row': ['163.965000', '2018']}, {'Row': ['153.371000', '2019']}, {'Row': ['161.864000', '2020']}]},}
查看完整描述