【问题标题】:Join two Dataframe table [duplicate]加入两个数据框表[重复]
【发布时间】:2018-06-11 14:03:39
【问题描述】:

我有两个数据框表:

df1

id A
1  wer
3  dfg
5  dfg

df2

id A
2  fgv
4  sdfsdf

我想将它加入到数据框中,看起来像这样:

df3

id A
1 wer
2 fgv
3 dfg

...

【问题讨论】:

标签: python pandas


【解决方案1】:
df3 = df1.merge(df2,how='outer',sort=True)

【讨论】:

    【解决方案2】:

    您可以使用 pandas 中的 concat 方法。

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


    您可以使用 -

    对索引进行排序

    df3 = df3.sort_index()


    或者像这样重置索引

    df3 = df3.reset_index(drop=True)

    我看到你的 df3 数据框末尾有省略号 (...),如果这意味着继续使用上面的数据框,请选择 Jibril's answer

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 2020-10-27
      • 2021-12-18
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      相关资源
      最近更新 更多