正确组合数据帧

Combining dataframes correctly

我有 3 个数据框需要水平连接。没有共同的专栏可以让我将它们联系在一起。我试过合并、加入、连接。可能是我写代码的时候做错了。

这是数据框1:

grill_type  is_frozen   item_material
0   Propane false   Hotdog
0   Propane true    Hotdog
0   Propane true    Hotdog
0   Propane false   Hotdog
0   Propane true    Hotdog

这是数据框2:

guess_grill_correct thumbs_up_score
0   true    0.4
0   true    1.0
0   true    0.0
0   true    0.0
0   true    0.4

这是数据框3:

sample_item_index
0   1
0   10
0   10
0   11
0   12

如你所见,三个数据帧都没有索引。

我想要这样的东西:

sample_item_index   item_material   is_frozen   grill_type  thumbs_up_score guess_grill_correct
0   1   Veggie Patty    False   Propane 0.0 True
1   1   Hotdog          False   Propane 0.4 True
2   2   Veggie Patty    True    Propane 0.9 True
3   3   Veggie Patty    False   Propane 0.8 True
4   4   Veggie Patty    True    Propane 0.8 True

当我尝试使用合并时,例如:

df1.merge(df2, on='index', how = 'left')

结果会多出很多卷,这不是我想要的

欢迎大家提出建议!

据我所知,您似乎想要连接。没有其他方法可以实现您想要的。请尝试

pd.concat([df1,df2,df3], axis=1)