I have a pandas dataframe that looks like this:
id | x1 | x2 | x3 | action |
---|---|---|---|---|
23432 | example1 | 1 | name | Create |
678786 | example2 | 1 | name | Create |
How can I convert that pandas dataframe to this json format?
[
{
"action": "Create",
"payload": {
"id": "23432",
"x1": "example1",
"x2": "1",
"x3": "name"
}
},
{
"action": "Create",
"payload": {
"id": "678786",
"x1": "example2",
"x2": "1",
"x3": "name"
}
}
]
I have played around with pd.json_normalize but can't get it to work. I also referenced this question but it's a bit different due to the need for groupby.