Convert Python dict into a dataframe

前端 未结 16 2392
暗喜
暗喜 2020-11-22 03:18

I have a Python dictionary like the following:

{u\'2012-06-08\': 388,
 u\'2012-06-09\': 388,
 u\'2012-06-10\': 388,
 u\'2012-06-11\': 389,
 u\'2012-06-12\':          


        
16条回答
  •  时光说笑
    2020-11-22 04:03

    As explained on another answer using pandas.DataFrame() directly here will not act as you think.

    What you can do is use pandas.DataFrame.from_dict with orient='index':

    In[7]: pandas.DataFrame.from_dict({u'2012-06-08': 388,
     u'2012-06-09': 388,
     u'2012-06-10': 388,
     u'2012-06-11': 389,
     u'2012-06-12': 389,
     .....
     u'2012-07-05': 392,
     u'2012-07-06': 392}, orient='index', columns=['foo'])
    Out[7]: 
                foo
    2012-06-08  388
    2012-06-09  388
    2012-06-10  388
    2012-06-11  389
    2012-06-12  389
    ........
    2012-07-05  392
    2012-07-06  392
    

提交回复
热议问题