Set column names in pandas data frame from_dict with orient = 'index'

后端 未结 3 1185
南方客
南方客 2021-01-01 17:12

I looked already at this question: pandas create named columns in dataframe from dict. However, my example is slightly different.

I have a dictionary: my_dict

3条回答
  •  失恋的感觉
    2021-01-01 17:40

    my_dict = {'key1' : [1,2,3], 'key2' : [4,5,6], 'key3' :[7,8,9]}
    df = pd.DataFrame.from_dict(my_dict, orient='columns')
    df.columns = ['one', 'two', 'three']
    

    Changed orient from index to columns. This worked for me.

提交回复
热议问题