在Python的pandas库中,可以使用concat()函数将不同列数的数据帧进行合并。下面是一个示例代码:
import pandas as pd
# 创建两个数据帧
df1 = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df2 = pd.DataFrame({'C': [7, 8, 9]})
# 使用concat()函数合并数据帧
df_combined = pd.concat([df1, df2], axis=1)
print(df_combined)
输出结果:
A B C
0 1 4 7
1 2 5 8
2 3 6 9
在以上代码中,首先创建了两个数据帧df1和df2。然后使用concat()函数将这两个数据帧按列合并,通过设置axis参数为1来指定按列合并。最后将合并后的数据帧赋值给df_combined,并打印输出。
上一篇:不同列数的Openquery性能
下一篇:不同列数据集之间的直方图问题