mercredi 27 juillet 2016

Pandas - count if multiple conditions

Having a dataframe in python:

CASE    TYPE
1          A
1          A
1          A
2          A
2          B
3          B
3          B
3          B

how can I create a result dataframe which would yield all cases and either an "A" if the case had only "A's" assigned, "B" if it was only "B's" or "MIXED" if the case had both A and B?

Result would be then:

Case     Type
1        A
2        MIXED
3        B

Aucun commentaire:

Enregistrer un commentaire