I have been trying to normalize a nested json but am struggling with is how to deal with NAN and empty fields as i am getting a => KeyError: 'address' when i am trying to normalize with
pd.json_normalize(data ,record_path=["address"],record_prefix='add.')
The data that i am using
data = [{
"id": "1",
"name": "test",
"last": "last"
}, {
"id": "2",
"name": "test1",
"last": "last1",
"address": []
},
{
"id": "2",
"name": "test2",
"last": "last2",
"address": [{
"steet": "streed2",
"no": 2
}]
}]
the ouptput i want
id | name | last | add.street | add.no
1 | test | last | NAN | NAN
2 | test1 | last1 | |
3 | test2 | last2 | street2 | 2