第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

大熊貓:每行適用哪個(gè)閾值?

大熊貓:每行適用哪個(gè)閾值?

給定分?jǐn)?shù)列,例如,scores = pd.DataFrame({"score":np.random.randn(10)})和閾值thresholds = pd.DataFrame({"threshold":[0.2,0.5,0.8]},index=[7,13,33])我想找到每個(gè)分?jǐn)?shù)的適用閾值,例如,      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   NaNIOW,對(duì)于每個(gè)分?jǐn)?shù),s我都希望閾值t使得t = min(t: thresholds.threshold[t] < s)我怎么做?PS。根據(jù)已刪除的答案:pd.cut(scores.score, bins=[-np.inf]+list(thresholds.threshold)+[np.inf],       labels=["low"]+list(thresholds.index))
查看完整描述

3 回答

?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以使用np.digitize以下方法實(shí)現(xiàn)它:


indeces = [None,] + thresholds.index.tolist()

scores["score"].apply(

    lambda x: indeces[np.digitize(x, thresholds["threshold"])])


查看完整回答
反對(duì) 回復(fù) 2021-04-13
?
肥皂起泡泡

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以merge_asof通過一些操作來獲得準(zhǔn)確的結(jié)果。


(pd.merge_asof( scores.reset_index().sort_values('score'), 

                thresholds.reset_index(), 

                left_on='score', right_on= 'threshold', suffixes = ('','_'))

     .drop('threshold',1).rename(columns={'index_':'threshold'})

     .set_index('index').sort_index())

并使用您的數(shù)據(jù),您將獲得:


          score  threshold

index                     

0     -1.613293        NaN

1     -1.357980        NaN

2      0.325720        7.0

3      0.116000        NaN

4      1.423171       33.0

5      0.282557        7.0

6     -1.195269        NaN

7      0.395739        7.0

8      1.072041       33.0

9      0.197853        NaN


查看完整回答
反對(duì) 回復(fù) 2021-04-13
  • 3 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)