0

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
1
  • {'id': '1.1, 'id': '1.2'} seems odd? Commented Mar 17, 2023 at 15:31

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.