I got an object in format:
{
"methodName_1": {
"version_1": "count",
"version_2": "count"
},
"methodName_2": {
"version_1": "count",
"version_2": "count"
},
...
}
How can I write it into excel in format:
version_1, version_2, ...
methodName_1: count, count, ...
methodName_2: count, count, ...
...
Thanks
CodePudding user response:
Use Dataframe
constructor and transpose or DataFrame.from_dict
, last write to excel by DataFrame.to_excel
:
df = pd.DataFrame(d).T
#alternative
#df = pd.DataFrame.from_dict(d, orient='index')
print (df)
version_1 version_2
methodName_1 count count
methodName_2 count count
df.to_excel('file.xlsx')