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

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

如何選擇滿足條件直到組的最后一個元素的 Pandas 數(shù)據(jù)幀?

如何選擇滿足條件直到組的最后一個元素的 Pandas 數(shù)據(jù)幀?

一只萌萌小番薯 2021-09-14 21:37:33
如何僅選擇val大于 5的行,直到每個id示例數(shù)據(jù)框中的最后一條記錄?df = pd.DataFrame({'id': [1,1,1,1,1,1,2,2,2,2,2,2],                   'val': [10,1,1,10,20,30,1,1,1,12,17,28]})id    val1      10  <- meets the condition, but condition fails in the next 2 rows1       11       11      10  <- meets the condition until the end of this id1      201      302       12       12       12      122      172      28期望的輸出:id    val1      101      201      302      122      172      28如果只有一個 id,我可以用一些難看的代碼來做到這一點,但我不知道如何將類似的邏輯應(yīng)用于所有組:df = pd.DataFrame({'id': [1,1,1,1,1,1],               'val': [10,1,1,10,20,30]})# create groups at breakpoints where condition is no longer metg = df.groupby((df['val'] > 5).cumsum())# find last grouplabel = max(list(g.groups.keys()))result = df.loc[g.groups[label]._data]# result still includes some rows where the condition is not metresult = result[result > 5]
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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