I need to generate a json from my dataframe but I have tried many formats of df but still I am not able get the required json format.
My required json format is,
[
{
"Keyword": "Red",
"values": [
{
"value": 5,
"TC": "Color"
}
]
},
{
"Keyword": "Orange",
"values": [
{
"value": 5,
"TC": "Color"
}
]
},
{
"Keyword": "Violet",
"values": [
{
"value": 5,
"TC": "Color"
}
]
}
]
I want a df to generate this json. Please help.
but currently im getting df.to_json:
{"Names":{"0":"Ram","1":"pechi","2":"Sunil","3":" Ravi","4":"sri"},"Values":{"0":"[{'value':2,'TC': 'TC Count'}]","1":"[{'value':2,'TC': 'TC Count'}]","2":"[{'value':1,'TC': 'TC Count'}]","3":"[{'value':1,'TC': 'TC Count'}]","4":"[{'value':1,'TC': 'TC Count'}]"}}
I think you need:
set_index
for columns not in nesteddictionaries
apply
withto_dict
reset_index
for column from indexto_json
For write to
file
: