dimanche 26 février 2017

python pandas flag if more than one unique row per value in column

In the following python pandas dataframe df, I have three columns:

   Code      |   Category  |    Count
     X               A          89734
     X               A          239487
     Y               B          298787
     Z               B          87980
     W               C          098454

I need to add a column, that if a category has more than one unique code (like B in the example above), it gets a flag denoting it as a test.

So the output I am looking for is this:

   Code      |   Category  |    Count    | Test_Flag
     X               A          89734       
     X               A          239487
     Y               B          298787         T
     Z               B          87980          T
     W               C          098454

Thank You.

Aucun commentaire:

Enregistrer un commentaire