擅长:python、mysql、java
<p>一种方法是合并两次。首先只使用百分位列,以便您可以向后填充:</p>
<pre><code>In [11]: merged = df1[['ksat']].merge(df2[['ksat', 'PERCENTILE']], how='outer', sort=True)
In [12]: merged
Out[12]:
ksat PERCENTILE
0 0.000000 NaN
1 0.100000 NaN
2 0.370684 1
3 0.400000 NaN
4 0.558053 2
5 0.794836 3
6 0.800000 NaN
7 0.962329 4
8 1.200000 NaN
9 1.202368 5
In [13]: merged.bfill()
Out[13]:
ksat PERCENTILE
0 0.000000 1
1 0.100000 1
2 0.370684 1
3 0.400000 2
4 0.558053 2
5 0.794836 3
6 0.800000 4
7 0.962329 4
8 1.200000 5
9 1.202368 5
</code></pre>
<p>然后与此结果合并:</p>
^{pr2}$