How to flatten a pandas dataframe with some columns as json?

后端 未结 4 882
日久生厌
日久生厌 2020-12-04 18:32

I have a dataframe df that loads data from a database. Most of the columns are json strings while some are even list of jsons. For example:

id           


        
4条回答
  •  醉梦人生
    2020-12-04 18:35

    The quickest seems to be:

    json_struct = json.loads(df.to_json(orient="records"))    
    df_flat = pd.io.json.json_normalize(json_struct) #use pd.io.json
    

提交回复
热议问题