1 回答
TA贡献1786条经验 获得超13个赞
您可以使用 pd.concat:
In [15]: df1 = pd.DataFrame({'month': [1, 1, 1, 1, 1, 1],
...: 'day': [2]*6,
...: 'station': ['A', 'B', 'C', 'D', 'E', 'F'],
...: 'mean': [55, 40, 84, 31, 44, 12],
...: 'sd': [1., 2., 1.2, 3., 4., 0.7]}).set_index(["station", "month", "day"])
In [16]: df2 = pd.DataFrame({'month': [2, 2, 2, 2, 2, 2],
...: 'day': [2]*6,
...: 'station': ['A', 'B', 'C', 'D', 'G', 'F'],
...: 'mean': [55, 40, 84, 31, 15, 12],
...: 'sd': [1., 2., 1.2, 3.,1, 0.7]}).set_index(["station", "month", "day"])
In [19]: pd.concat([df1,df2]).sort_index()
Out[19]:
mean sd
station month day
A 1 2 55 1.0
2 2 55 1.0
B 1 2 40 2.0
2 2 40 2.0
C 1 2 84 1.2
2 2 84 1.2
D 1 2 31 3.0
2 2 31 3.0
E 1 2 44 4.0
F 1 2 12 0.7
2 2 12 0.7
G 2 2 15 1.0
添加回答
举报