Column order in pandas.concat

后端 未结 6 1674
既然无缘
既然无缘 2021-02-04 00:26

I do as below:

data1 = pd.DataFrame({ \'b\' : [1, 1, 1], \'a\' : [2, 2, 2]})
data2 = pd.DataFrame({ \'b\' : [1, 1, 1], \'a\' : [2, 2, 2]})
frames = [data1, data2         


        
6条回答
  •  佛祖请我去吃肉
    2021-02-04 00:50

    Starting from version 0.23.0, you can prevent the concat() method to sort the returned DataFrame. For example:

    df1 = pd.DataFrame({ 'a' : [1, 1, 1], 'b' : [2, 2, 2]})
    df2 = pd.DataFrame({ 'b' : [1, 1, 1], 'a' : [2, 2, 2]})
    df = pd.concat([df1, df2], sort=False)
    

    A future version of pandas will change to not sort by default.

提交回复
热议问题