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

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

如何獲取熊貓中頻率較低的行的索引

如何獲取熊貓中頻率較低的行的索引

素胚勾勒不出你 2021-10-05 17:07:23
如何獲得計(jì)數(shù)值較少的行的索引。例如:test = pd.DataFrame({'price' : [1, 2, 1, 3, 5, 2, 2]})out[1]:    price0   11   22   13   34   55   26   2我怎樣才能得到 price = 1, 3 ,5 的索引,它在列中只出現(xiàn)少于 3 次?
查看完整描述

2 回答

?
MM們

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

使用 duplicated


test[~test.price.duplicated(keep=False)]

   price

3      3

4      5

test.index[~test.price.duplicated(keep=False)]

Int64Index([3, 4], dtype='int64')

更新然后你需要 transform


test[test.groupby('price').price.transform('count')<=1]

   price

3      3

4      5


test[test.groupby('price').price.transform('count')<3].index

Int64Index([0, 2, 3, 4], dtype='int64')


查看完整回答
反對 回復(fù) 2021-10-05
?
慕勒3428872

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

您可以計(jì)算物品value_counts并選擇“足夠稀有”的物品:


THRESHOLD = 3

is_rare = test['price'].value_counts() < THRESHOLD

rare = is_rare[is_rare].index

#Int64Index([1, 5, 3], dtype='int64')

接下來,找到包含稀有物品的行:


are_rare_rows = test["price"].isin(rare)

are_rare_rows[are_rare_rows].index

#Int64Index([0, 2, 3, 4], dtype='int64')


查看完整回答
反對 回復(fù) 2021-10-05
  • 2 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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