在 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
我尝试使用append和concat,但是似乎没有任何效果.任何帮助将不胜感激.
I have tried using append and concat but nothing seems to work. Any help would be much appreciated.
答
连接数据框
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