3 回答

TA贡献1906条经验 获得超3个赞
一种简单的方法是设置索引,depth然后使用depth数组重新索引:
df1.set_index('depth').reindex(depth).reset_index()
depth 400.0 401.0 402.0 403.0 404.0 405.0
0 0.8 13.909261 14.581624 15.253988 15.633908 15.991816 16.349725
1 0.9 7.758734 8.173803 8.588872 8.833914 9.066159 9.298403
2 1.0 3.513627 3.757856 4.002085 4.146499 4.283401 4.420303
3 1.1 2.095409 2.223524 2.351638 2.431543 2.507818 2.584094
4 1.2 1.628918 1.695623 1.762327 1.798185 1.831721 1.865257
5 1.3 0.782643 0.818065 0.853486 0.874350 0.894119 0.913887
6 1.4 0.278548 0.300235 0.321922 0.333470 0.344256 0.355041
7 1.5 0.160153 0.173674 0.187195 0.192128 0.196415 0.200702
8 1.6 -0.155895 -0.145402 -0.134910 -0.130119 -0.125758 -0.121396
9 1.7 -0.152373 -0.144456 -0.136539 -0.134795 -0.133516 -0.132237
10 1.8 -0.147820 -0.142969 -0.138118 -0.136049 -0.134189 -0.132330
11 1.9 -0.023997 -0.022471 -0.020945 -0.019307 -0.017659 -0.016012
12 2.0 0.010729 0.010802 0.010875 0.012037 -0.013281 0.014525
13 2.1 0.006050 0.006181 0.006313 0.006674 0.007053 0.007433
14 2.2 0.002356 0.002641 0.002927 0.003002 0.003061 0.003120
15 2.3 NaN NaN NaN NaN NaN NaN
16 2.4 NaN NaN NaN NaN NaN NaN
17 2.5 NaN NaN NaN NaN NaN NaN

TA贡献1818条经验 获得超8个赞
使用 combine_first
>>> pd.DataFrame({'depth':depth}).combine_first(df1)
使用 pd.concat
>>> pd.concat([pd.DataFrame({'depth':depth}), df1.iloc[:,1:]], 1)
添加回答
举报