I have an excel sheet that looks as follows:
I would like to create from this table a JSON that looks like this:
{
"lion": [{
"a": 0,
"b": 1,
"c": 23,
"d": 55
}, {
"a": 1,
"b": 23,
"c": 32,
"d": 24
}],
"king": [{
"a": 55,
"b": 66,
"c": 77,
"d": 88
}]
}
In order to do so, I tried the following:
import pandas;
import json;
excel_data = pandas.read_excel('my_excel.xlsx', sheet_name = 'sheet1')
for index, row in excel_data.iterrows():
row.dropna(inplace = True) # for cases when Nan
d = row.to_dict()
j = json.dumps(d)
however, the result i'm getting is a JSON without the required structure:
{"name": 'lion',"a": 0,"b": 1,"c": 23,"d": 55,"a": 1,"b": 23,"c": 32,"d": 24}
how can I split it so it would look like the JSON I need?
Thank you
