pandas.io.json.json_normalize with very nested json

后端 未结 2 903
野性不改
野性不改 2020-11-30 00:04

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.

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 00:31

    You can also have a look at the library flatten_json, which does not require you to write column hierarchies as in json_normalize:

    from flatten_json import flatten
    
    data = d['hits']['hits']
    dict_flattened = (flatten(record, '.') for record in data)
    df = pd.DataFrame(dict_flattened)
    print(df)
    

    See https://github.com/amirziai/flatten.

提交回复
热议问题