Skip to content
Advertisement

How can I transform a pandas df to this kind of json structure?

Let’s say I have a pandas df like this:

JavaScript

I would like to transform it in a json format like this:

JavaScript

How can I do this? The nearest match I had was using df.to_json(orient="index") but what I’ve got was a structure like this:

JavaScript

Would be really thankful for any help!

Advertisement

Answer

Use df.to_dict('records')

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement