Turning my dictionary into a pandas dataframe

后端 未结 4 1147
一生所求
一生所求 2021-01-19 23:01

I have a function which create several dicts of dicts, based on some conditions.

However, I would really like to turn the dict into a dataframe after collecting it.

4条回答
  •  感情败类
    2021-01-19 23:28

    refer: Construct pandas DataFrame from items in nested dictionary

    df = pd.DataFrame.from_dict({(i,j): dict_[i][j][z] 
                                   for i in dict_.keys() 
                                   for j in dict_[i].keys()
                                   for z in dict_[i][j].keys()},
                               orient='index')
    df
    
    
               lowPrice   lowDate  highPrice  highDate  change
    TSLA 2011    185.16  05/27/19     365.71  12/10/18   -0.49
         2012    185.16  05/27/19     365.71  12/10/18   -0.49
         2013     32.91  01/07/13     190.90  09/23/13    4.80
    

提交回复
热议问题