Convert JSON file to Pandas dataframe

后端 未结 4 1496
醉话见心
醉话见心 2021-02-09 23:40

I would like to convert a JSON to Pandas dataframe.

My JSON looks like: like:

{ 
   \"country1\":{ 
      \"AdUnit1\":{ 
         \"floor_price1\":{ 
            


        
4条回答
  •  青春惊慌失措
    2021-02-10 00:10

    You can try this approach:

     from google.cloud import storage
     import pandas as pd
    
     storage_client = storage.Client()
     bucket = storage_client.get_bucket('test-mvladoi')
     blob = bucket.blob('file')
     read_output = blob.download_as_string()
     data = json.loads(read_output)
    
     data_norm = json_normalize(data, max_level=5)
     df = pd.DataFrame(columns=['col1', 'col2', 'col3', 'col4', 'col5'])
     i = 0
    
     for col in b.columns:
         a,c,d,e = col.split('.')
         df.loc[i]  = [a,c,d,e,b[col][0]]
         i = i + 1
    
     print(df)
    

提交回复
热议问题