I have a below json , which I need to convert into dataframe
{'res':[{'columns':['col1','col2','col3'],'data':[{'row':['aaa','123','qqq'],'met':['none','none','none']},{'row':['bbb','456','rrr'],'met':['none','none','none']},
{'row':['ccc','789','sss'],'met':['none','none','none']}]}],'err':[]}
as
CodePudding user response:
Try:
data = {
"res": [
{
"columns": ["col1", "col2", "col3"],
"data": [
{"row": ["aaa", "123", "qqq"], "met": ["none", "none", "none"]},
{"row": ["bbb", "456", "rrr"], "met": ["none", "none", "none"]},
{"row": ["ccc", "789", "sss"], "met": ["none", "none", "none"]},
],
}
],
"err": [],
}
df = pd.DataFrame(
[d["row"] for d in data["res"][0]["data"]],
columns=data["res"][0]["columns"],
)
print(df)
Prints:
col1 col2 col3
0 aaa 123 qqq
1 bbb 456 rrr
2 ccc 789 sss