I have a data frame df
df:
col1 col2 col3
1 2 3
4 5 6
7 8 9
The json I am looking for is:
{
"col1": 1,
"col1": 4,
"col1": 7,
},
{
"col2": 2,
"col2": 5,
"col2": 8
},
{
"col3": 3,
"col3": 6,
"col3": 9,
}
I have tries df.to_json but its not working
df.to_json(orients=records)
it gives this output
'[{"col1":1,"col2":2,"col3":3},{"col1":4,"col2":5,"col3":6},
{"col1":7,"col2":8,"col3":9}]
This is not the output i was looking for
How to do it in most effective way using pandas/python ?
df.to_json(orient='records')orientS, butorientlines=Trueis what you need