Every customer is duplicated when they have more than one plan. I want to set the status to the customer:
If they have every product with 'canceled_at' filled, the customer status is cancelled, but when it's not every product with the canceled_at filled, but at least one, the status is 'downgrade' because he lost a product.
customer|canceled_at|status
x |3/27/2018 |
x | |
y |2/2/2018 |
y |2/2/2018 |
z |1/1/2018 |
a | |
I already have the canceled status, now i only need the downgrade
df['status']=(df.groupby('customer')['canceled_at'].
transform(lambda x: x.notna().all()).map({True:'canceled'})).fillna(df.status)
customer|canceled_at|status
x |3/27/2018 |downgrade
x | |downgrade
y |2/2/2018 |canceled
y |2/2/2018 |canceled
z |1/1/2018 |canceled
a | |