给定分数列,例如,
scores = pd.DataFrame({"score":np.random.randn(10)})
和阈值
thresholds = pd.DataFrame({"threshold":[0.2,0.5,0.8]},index=[7,13,33])
我想找到每个分数的适用阈值,例如,
score threshold
0 -1.613293 NaN
1 -1.357980 NaN
2 0.325720 7
3 0.116000 NaN
4 1.423171 33
5 0.282557 7
6 -1.195269 NaN
7 0.395739 7
8 1.072041 33
9 0.197853 NaN
IOW,对于每个分数,s我都希望阈值t使得
t = min(t: thresholds.threshold[t] < s)
我怎么做?
PS。根据已删除的答案:
pd.cut(scores.score, bins=[-np.inf]+list(thresholds.threshold)+[np.inf],
labels=["low"]+list(thresholds.index))
梵蒂冈之花
肥皂起泡泡
相关分类