Looking for ways to filter unique values with inactive
status, but not repeated as active
status under the same unique value.
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)
Desired output:
Unique_value status
2 Inactive
3 Inactive
What I tried so far, but I don't think this is correct.
p = ['Inactive', 'Active']
df.groupby('Unique_value')['Status'].apply(lambda x: (x =='Inactive') != set(p))
question from:
https://stackoverflow.com/questions/65853855/filtering-column-value-based-on-unique-value-but-not-repeated-for-different-val 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…