給定一個數(shù)據(jù)框{'id': {0: 100, 1: 100, 2: 101, 3: 101, 4: 102}, 'A': {0: True, 1: False, 2: True, 3: False, 4: True}, 'B': {0: False, 1: True, 2: False, 3: True, 4: False}, 'C': {0: False, 1: False, 2: False, 3: False, 4: False}}看起來像這樣我們?nèi)绾魏喜⑿校员忝總€唯一 id 只有一行,并保留所有 True 值?目標:用途groupby.max:df.groupby('id', as_index=False).max()
1 回答

MM們
TA貢獻1886條經(jīng)驗 獲得超2個贊
嘗試用
out = df.groupby('id').max().reset_index()
自從
True > False
return : True
添加回答
舉報
0/150
提交
取消