【发布时间】:2021-01-22 22:54:46
【问题描述】:
寻找过滤具有inactive 状态的唯一值的方法,但在相同的唯一值下不重复为active 状态。
df:
Unique_value Status
1 Active <- Has both active and inactive, must be inactive only
1 Active <- Has both active and inactive, must be inactive only
1 Inactive <- Has both active and inactive, must be inactive only
1 Inactive <- Has both active and inactive, must be inactive only
2 Inactive <- Has inactive only
2 Inactive <- Has inactive only
2 Inactive <- Has inactive only
3 Inactive <- Has inactive only (cancelled okay to be filtered out)
3 Cancelled <- Has inactive only (cancelled okay to be filtered out)
3 Inactive <- Has inactive only (cancelled okay to be filtered out)
期望的输出:
Unique_value status
2 Inactive
3 Inactive
到目前为止我尝试过的,但我认为这是不正确的。
p = ['Inactive', 'Active']
df.groupby('Unique_value')['Status'].apply(lambda x: (x =='Inactive') != set(p))
【问题讨论】:
标签: python-3.x pandas dataframe lambda apply