给定一个数据框
{'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}}
看起来像这样
我们如何合并行,以便每个唯一 id 只有一行,并保留所有 True 值?
目标:
用途groupby.max
:
df.groupby('id', as_index=False).max()
MM们
相关分类