1 回答
TA贡献1900条经验 获得超5个赞
您可以使用np.select以下方法来执行此操作:
cond1 = df['value'] <= df['Min']
cond2 = df['value'] <= df['P25']
cond3 = df['value'] <= df['P50']
cond4 = df['value'] <= df['P75']
cond5 = df['value'] < df['Max']
df['rank'] = np.select([cond1, cond2, cond3, cond4, cond5], [1,2,3,4,5], 6)
df
输出:
date value Min P25 P50 P75 Max output rank
1 1-Sep 45.0 12.0 28.2 48.9 85.4 98.0 3.0 3
2 2-Sep 63.0 12.0 28.2 48.9 85.4 98.0 4.0 4
3 3-Sep 87.0 12.0 28.2 48.9 85.4 98.0 5.0 5
4 4-Sep 12.0 12.0 28.1 48.9 85.2 98.0 1.0 1
5 5-Sep 89.0 14.2 28.8 48.9 85.8 98.0 5.0 5
6 6-Sep 98.0 14.2 28.8 48.9 85.8 98.0 6.0 6
7 7-Sep 41.0 14.2 28.8 48.9 85.6 97.9 3.0 3
8 8-Sep 22.0 14.2 28.8 48.9 85.6 97.9 2.0 2
添加回答
举报