【问题标题】:Append dataframes while ignoring column names在忽略列名的同时附加数据框
【发布时间】:2021-03-31 01:40:46
【问题描述】:

我有一个循环,每次迭代都会生成一个数据帧。

DimensionAll=[]
for i in range(0,10):
    ###code here###
    DimensionAll.append(MatrixDimension)

其中MatrixDimension如下:

       Cameroun    Rwanda     Niger    Zambia      Mali    Angola  Ethiopia  
 ECON  0.092811  0.088966  0.077843  0.101176  0.080969  0.045516  0.084101   
 FOOD  0.052086  0.035915  0.037474  0.025168  0.039382  0.015079  0.083499   
 ENV   0.018479  0.043677  0.004737  0.003744  0.009258  0.034044  0.010285   
 HEA   0.000061  0.029189  0.012335  0.001238  0.019010  0.007995  0.017359   
 PERS  0.056941  0.005222  0.048715  0.030879  0.070985  0.064726  0.023330   
 COM   0.000000  0.000000  0.000000  0.000000  0.009809  0.005251  0.099614   
 POL   0.025177  0.090846  0.005273  0.029481  0.001929  0.065365  0.034342  

追加时如何忽略列名?每次迭代后是否有不同的方法来附加或连接数据帧(同时将列名保持在顶部而不重复)?

【问题讨论】:

    标签: python-3.x dataframe append concatenation


    【解决方案1】:

    这段代码给了我想要的答案:

    DimensionAll=[]
    for i in range(0,10):
        ###code here###
        DimensionAll.append(MatrixDimension)
    DimensionAll= pd.concat(DimensionAll)
    

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 2019-12-06
      • 2010-12-05
      • 2021-04-17
      • 2017-05-04
      • 2018-08-20
      • 2019-09-09
      • 2022-08-16
      • 1970-01-01
      相关资源
      最近更新 更多