【发布时间】:2020-03-05 23:33:48
【问题描述】:
我有 2 个数据框如下:
df1 =
City Date Data1
LA 2020-01-01 20
LA 2020-01-02 30
NY 2020-01-01 50
df2 =
City Date Data2
LA 2020-01-01 2.5
LA 2020-01-02 1
LA 2020-01-03 7
NY 2020-01-01 6.5
我想根据“城市”和“日期”合并或连接它们,这样结果将是:
City Date Data1 Data2
LA 2020-01-01 20 2.5
LA 2020-01-02 30 1
NY 2020-01-01 50 6.5
我尝试了什么:
pd.concat([df1.set_index(['Country','Date'],[df1.set_index(['Country','Date'])], axis = 1)
我得到错误: ValueError: 无法处理非唯一的多索引!
我也不能合并,因为我有日期作为索引。
【问题讨论】: