I have a dataframe df as shown below
ID Aisle Residence HomePhone CellPhone
------------------------------------------------------------------------------
0 1245,3214 A1, A2, A3, A4 Home NaN 888888888
1 5674 B2,B3 Cell 777777777 999999999
Expected outcome:
{
"0":{
{
"column": "ID",
"values": [
"1245",
"3214"
]
},
{
"column": "Aisle",
"values": [
"A1",
"A2",
"A3",
"A4"
]
},
{
"column": "Residence",
"values": [
"Home"
]
},
{
"column": "HomePhone",
"values": []
},
{
"column": "CellPhone",
"values": [
"888888888"
]
}
},
"1":{
{
"column": "ID",
"values": [
"5674"
]
},
{
"column": "Aisle",
"values": [
"B2",
"B3"
]
},
{
"column": "Residence",
"values": [
"Cell"
]
},
{
"column": "HomePhone",
"values": [
"777777777"
]
},
{
"column": "CellPhone",
"values": [
"999999999"
]
}
},
I have 2 rows which are 0 and 1, and the json has the information under them for each row.
So basically, I want to add attributes and assign them to values that are column names, such as "column":"Aisle","values":["A1","B1,...]"
Also, I have a restriction that the column names always change (ID, Aisle, Residence...etc) and the number of columns vary, so I cannot hard code columns when converting from DF to JSON.