Column order in pandas.concat

后端 未结 6 1658
既然无缘
既然无缘 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:56

    You can create the original DataFrames with OrderedDicts

    from collections import OrderedDict
    
    odict = OrderedDict()
    odict['b'] = [1, 1, 1]
    odict['a'] = [2, 2, 2]
    data1 = pd.DataFrame(odict)
    data2 = pd.DataFrame(odict)
    frames = [data1, data2]
    data = pd.concat(frames)
    data
    
    
        b    a
    0   1    2
    1   1    2
    2   1    2
    0   1    2
    1   1    2
    2   1    2
    

提交回复
热议问题