Flatten Pandas DataFrame from nested json list

前端 未结 1 1234
我在风中等你
我在风中等你 2020-12-21 16:01

perhaps somebody could help me. I tried to flat the following ist into a pandas dataframe:

[{u\'_id\': u\'2\',
  u\'_index\': u\'list\',
  u\'_score\': 1.41         


        
相关标签:
1条回答
  • 2020-12-21 16:34

    Use json_normalize:

    from pandas.io.json import json_normalize  
    
    df = json_normalize(data)
    print (df)
      _id _index    _score _source.dat _source.name _type
    0   2   list  1.414214         NaN        name3   doc
    1   5   list  1.414214  2016-12-12        name2   doc
    2   1   list  1.414214         NaN        name1   doc
    
    0 讨论(0)
提交回复
热议问题