Skip to content Skip to sidebar Skip to footer

Json_normalize For Dicts Within Dicts

I have been trying to normalize a very nested json file I will later analyze. What I am struggling with is how to go more than one level deep to normalize. I went through the panda

Solution 1:

In [23]: lst = [l for l in raw['hits']['hits'] if l['_source'].get('authors')]

In [24]: json_normalize(lst, 
                        [['_source', 'authors']], 
                        ['_id', ['_source', 'journal'], ['_source', 'title']])
Out[24]:
           affiliations author_id          author_name       _id                                    _source.journal  \
0  [Punjabi University]  780E3459          munish puri  7AF8EBC3  Journal of Industrial Microbiology & Biotechno...
1  [Punjabi University]  48D92C79      rajesh dhaliwal  7AF8EBC3  Journal of Industrial Microbiology & Biotechno...
2  [Punjabi University]  7D9BD37C            r s singh  7AF8EBC3  Journal of Industrial Microbiology & Biotechno...
3                   NaN  7FF872BC  barbara eileen ryan  7521A721                     The American Historical Review
4                   NaN  0299B8E9     fraser j harbutt  7DAEB9A4                     The American Historical Review
5                   NaN  7DAB7B72   richard m freeland  7B3236C5                     The American Historical Review

                                       _source.title
0  Development of a stable continuous flow immobi...
1  Development of a stable continuous flow immobi...
2  Development of a stable continuous flow immobi...
3  Feminism and the women's movement : dynamics o...
4  The iron curtain : Churchill, America, and the...
5  The Truman Doctrine and the origins of McCarth...

Post a Comment for "Json_normalize For Dicts Within Dicts"