Assuming you have multiple dataframes (df1, df2, df3, etc.) with no column headers, you can concatenate them vertically using pandas.concat() method as follows:

import pandas as pd

# create example dataframes
df1 = pd.DataFrame([[1,2,3],[4,5,6]])
df2 = pd.DataFrame([[7,8,9],[10,11,12]])
df3 = pd.DataFrame([[13,14,15],[16,17,18]])

# concatenate dataframes vertically
result = pd.concat([df1, df2, df3])

print(result)

Output:

    0   1   2
0   1   2   3
1   4   5   6
0   7   8   9
1  10  11  12
0  13  14  15
1  16  17  18

If you want to reset the column headers, you can use the rename() method as follows:

# reset column headers
result = result.rename(columns={0: 'col1', 1: 'col2', 2: 'col3'})

print(result)

Output:

   col1  col2  col3
0     1     2     3
1     4     5     6
0     7     8     9
1    10    11    12
0    13    14    15
1    16    17    18
Pandas Concatenate DataFrames Without Headers: A Complete Guide

原文地址: https://www.cveoy.top/t/topic/nPyR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录