Suppose that we have a Pandas DataFrame (df) as:
| nickname | event | Date |
|---|---|---|
| A | 0 | 2020-01-02 |
| A | 1 | 2020-01-03 |
| B | 0 | 2020-01-02 |
| B | 0 | 2020-01-03 |
| C | 1 | 2020-01-02 |
| C | 1 | 2020-01-03 |
Is there a quick and elegant way of getting only the lines where the nickname has never had an 1 event? Like
| nickname | event | Date |
|---|---|---|
| B | 0 | 2020-01-02 |
| B | 0 | 2020-01-03 |
I came up with the following code to solve this problem
df_group= df.groupby('nickname')['event'].max()
df_never = df_group[df_group == 0]
df_only_never = df[df['nickname'].isin(df_never .index)]
I have the feeling that there is a one-line way of doing this with Pandas, but I'm not sure how to do it.