0

I have a df with name and status with present and absent as values.

            name     status
    0      anthony   present
    1      anthony   absent
    2      mason     present
    3      donny     present
    4      donny     absent
    5      donny     absent
    6      paul      present
    7      paul      present

I'm trying to put status - True or False for each name.

If one of the name has absent their status will be False

Expected Output:

            name     output
    0      anthony   False
    1      mason     True
    2      donny     False
    3      paul      True

2 Answers 2

1

You can compare status to 'present' then get the mininum by name:

# or `all()` instead of `min()`
df['status'].eq('present').groupby(df['name']).min()

Output:

name
anthony    False
donny      False
mason       True
paul        True
Name: status, dtype: bool
Sign up to request clarification or add additional context in comments.

Comments

0

Another way is to groupby name and find if a name has present as the only status.

df.groupby('name')['status'].apply(lambda x: (x=='present').all())



    name
    anthony    False
    donny      False
    mason       True
    paul        True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.