Python DF to Json Format. with primitive and nested dict

Issue

This Content is from Stack Overflow. Question asked by D P

i have a dataframe i wanted to convert into a specific json format but im quite stuck due to the primitive and nested dict format.

data = {
  "id": ['1', '2'],
  "route_platform": ['data-sets,profile,users,workspaces', ' profile,workspaces'],
  "lastactivity_platform": ['2022-09-19T03:44:40.163Z', '2022-09-08T05:51:07.783Z'],
  "properties": ['properties', 'properties'],
}
df = pd.DataFrame(data)

and i wanted to convert it to this kind of format:

    inputs=[{'id':'1',
             'properties':
                 {
                    'route_platform':'data-sets,profile,users,workspaces','lastactivity_platform':'2022-09-19T03:44:40.163Z',
                 }
             },
            {'id':'2',
             'properties':
                 {
                    'route_platform':'profile,workspaces','lastactivity_platform':'2022-09-08T05:51:07.783Z',
                 }
             },
            ]



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?