串联不同长度的熊猫数据帧

时间:2019-03-27 15:16:30

标签: python pandas

我有几个空的数据框,它们的长度都不同,它们共享一些公共字段,但是每个数据框也有一些唯一的列。在尝试连接它们时,我不断得到ValueError: Plan shapes are not aligned

cols1 = ['Test', 'Col1', 'Col2']
cols2 = ['Test', 'Col1', 'Col2', 'Date']
cols3 = ['Test', 'Col1', 'Col2', 'Time']

df1 = pd.DataFrame(columns=cols1)
df2 = pd.DataFrame(columns=cols2)
df3 = pd.DataFrame(columns=cols3)

df_dict = {'project': [df1, df2, df3]}
for table, dfs in df_dict.items():
    result = pd.concat(dfs)

理想情况下,我的输出应具有如下所示的列列表:

['Test1', 'Col1', 'Col2', 'Date', 'Time']

是否有任何方法可以使用Merge来完成 。我不想使用Merge,因为我并不总是知道共享的列,等等。

0 个答案:

没有答案
相关问题