Suppose a list of objects: one, two, three,...
Every object is composed of name, foo1, and foo2 fields.
[{
'name':'one',
'foo2':{
'id':'1.1',
'id':'1.2'
},
'foo1':[
{
'foo2':{
'id':'1.1',
'name':'one.one'
}
},
{
'foo2':{
'id':'1.2',
'name':'one.two'
}
}
]
}]
If the object is normalize using:
obj_row_normalize = pd.json_normalize( object_row,
record_path =['foo2'],
meta=['name'],
record_prefix='num_',
)
The result is:
id num_name
1.1 one
1.2 one
Given that, how can foo1.foo2.name be added to each resulting row as below:
id num_name name
1.1 one one.one
1.2 one one.two
Change the record path to foo1
:
pd.json_normalize(recs, record_path=['foo1'], meta='name')
foo2.id foo2.name name
0 1.1 one.one one
1 1.2 one.two one