I have this DataFrame: All the dataframe fields are ASCII strings and is the output from a SQL query (pd.read_sql_query) so the line to create the dataframe above may not be quite right. And I wish the final JSON output to be in the form I realize that may not be ‘normal’ JSON but that is the format expected by
Tag: to-json
How can I transform a pandas df to this kind of json structure?
Let’s say I have a pandas df like this: I would like to transform it in a json format like this: 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: Would be really thankful for any help! Answer Use df.to_dict(‘records’)
How to convert dataframe column into list of lists json format?
My dataframe looks like below and I want to use sales column and convert it into json files for each month as a list of lists. sales dt 156 2022-01 192 2022-01 147 2022-02 192 2022-02 Using this, I am getting this format of json files: However, I want to have: I have created this as a toy example. I