I am trying to convert the dataframe mentioned below to desired json
column_id,column_name,mandatory,column_data_type,column_data_length,_id,data_format,file_type,active_ind
1,PAT_ID,FALSE,VARCHAR,2500,5f2193c39448c44f0c1b65e0,TEXT,FACT,TRUE
2,PAT_NAME,FALSE,VARCHAR,2500,5f2193c39448c44f0c1b65e0,TEXT,FACT,TRUE
3,PAT_AGE,FALSE,VARCHAR,2500,5f2193c39448c44f0c1b65e0,TEXT,FACT,TRUE
Like the json mentioned below
{
"_id": 5f2193c39448c44f0c1b65e0,
"data_format": "TEXT",
"file_type": "FACT",
"columns": [
{
"column_id": 1,
"column_name": "PAT_ID",
"mandatory": "false",
"column_data_type": "VARCHAR",
"column_data_length": 2500
},
{
"column_id": 2,
"column_name": "PAT_NAME",
"mandatory": "false",
"column_data_type": "VARCHAR",
"column_data_length": 2500
}
],
"active_ind": "true",
}
I tried to group by based on column name and column id with so many methods
this will group column but not all the values
cac= df.groupby('column_id').apply(lambda x: x.to_json(orient='records'))cac = df.to_json(orient='records')
I am not able to separate the id and columns.
Please help me on this