I have a dataframe which contains nested columns as below when converted in to json format.
{"id" : 1,
"address":
{"adress1":"",
"city" : "TX",
"zip": ""
},
"gender": "",
"code": 999
}
The dataframe is normalized and will be written in to snowflake variant column. I would like to replace empty values("") with nulls before it inserted in to snowflake.
I tried using df.replace('',np.NAN, inPlace='True)
. But it replaced only gender with null. I am not able to see address1 and zip value with nulls. They are still empty. Can someone help how we can handle this scenario.
2
Answers
Try this approach:
for your particular case you can use for loops to replace
''
withnp.nan
You can use nested loops to filtrate inside 2 level of json. If you have more levels of nested you can use more forloops in try block: