我是Python的新手,需要您的帮助。
我有两个数据框需要加入(或合并或连接?)。
第一个具有多级列名称:
df1:
Station New Station
X 125032
Y 6563255
Z 1500
Sensor P T
Category Precipitation Temperature
Unit mm/d C
Interpolation ConstantAfter Linear
1979-10-01 0.16352 -4.00487
1979-10-02 0.67616 -4.54372
1979-10-03 0.41640 -5.32490
1979-10-04 0.10048 -5.02924
第二个是df2:
Category Temperature Precipitation
2015-06-11 1.35931 0.28088
2015-06-12 1.47636 1.07184
2015-06-13 4.32775 0.67992
2015-06-14 3.06252 7.99056
2015-06-15 -2.76417 0.00576
2015-06-16 1.82125 0.28592
有关信息:
df1.to_dict()={('New Station', '125032', '6563255', '1500', 'P',
'Precipitation', 'mm/d', 'ConstantAfter'): {Timestamp('1979-10-01
00:00:00'): 0.16352, Timestamp('1979-10-02 00:00:00'): 0.67615999999999998,
Timestamp('1979-10-03 00:00:00'): 0.41639999999999999, Timestamp('1979-10-04
00:00:00'): 0.10048}, ('New Station', '125032', '6563255', '1500', 'T',
'Temperature', 'C', 'Linear'): {Timestamp('1979-10-01 00:00:00'):
-4.0048699999999995, Timestamp('1979-10-02 00:00:00'): -4.5437199999999995,
Timestamp('1979-10-03 00:00:00'): -5.3249000000000004, Timestamp('1979-10-04
00:00:00'): -5.0292399999999997}}
我的问题:如何将两个数据帧合并到一个数据帧中,以确保温度数据最终出现在温度列中,而降水数据最终出现在降水量列中?最终数据框应具有多级列名称。
非常感谢您