[英]Merging two dataframes with same column names but different number of columns in pandas
I have two pandas dataframes 我有两个pandas数据帧
df1 = DataFrame([[0,123,321],[0,1543,432]], columns=['A', 'B','C'])
df2 = DataFrame([[1,124],[1,1544]], columns=['A', 'C'])
I want to merge these so that the new dataframe would look like below 我想合并这些,以便新的数据框如下所示
A | B | C
0 123 321
0 1543 432
1 null 124
1 null 1544
I have tried using append and concat but nothing seems to work. 我尝试过使用append和concat,但似乎没有任何效果。 Any help would be much appreciated.
任何帮助将非常感激。
Concatenate the dataframes 连接数据帧
import pandas as pd
pd.concat([df1,df2], axis=0)
A B C
0 0 123 321
1 0 1543 432
0 1 NaN 124
1 1 NaN 1544
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.