Convert Python dict into a dataframe

前端 未结 16 2667
暗喜
暗喜 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 03:59

    In my case I wanted keys and values of a dict to be columns and values of DataFrame. So the only thing that worked for me was:

    data = {'adjust_power': 'y', 'af_policy_r_submix_prio_adjust': '[null]', 'af_rf_info': '[null]', 'bat_ac': '3500', 'bat_capacity': '75'} 
    
    columns = list(data.keys())
    values = list(data.values())
    arr_len = len(values)
    
    pd.DataFrame(np.array(values, dtype=object).reshape(1, arr_len), columns=columns)
    

提交回复
热议问题