【发布时间】:2014-10-15 15:04:19
【问题描述】:
假设我有两个具有不同索引的不同熊猫数据框 例如:
df1:
email | other_field
_________________________________________
email1@email.com | 2
email2@email.com | 1
email3@email.com | 6
和df2:
new_field
__________
1
7
4
这 2 个数据框的大小相同。 我怎样才能合并它们两个以获得类似的输出?
df3:
email | other_field | new_field
________________________________________________________________
email1@email.com | 2 | 1
email2@email.com | 1 | 7
email3@email.com | 6 | 4
我试过了:
df3 = pd.merge(df1, df2, left_index=True, right_index=True)
尽管 df1 和 df2 的大小相同,但 df3 的大小较小
【问题讨论】:
-
如果长度相同,你可以连接
pd.concat([df1,df2], axis=1, ignore_index=True)
标签: python pandas merge dataframe