Here is my dataframe:
ID Color
0 1 red
1 1 blue
2 1 yellow
3 2 blue
4 2 purple
5 3 yellow
6 3 green
I want to create a third column that tells me whether there is a color red or yellow for each ID. If there is a red then the third column will be 1, if there is a purple then the third column will be 0, if there are neither it stays blank. There will be no cases that red and purple will be in the same ID.
So, my resultant df should look like this:
ID Color col3
0 1 red 1
1 1 blue 1
2 1 yellow 1
3 2 blue 0
4 2 purple 0
5 3 yellow
6 3 green
I'm thinking about doing a groupby on my ID column, then checking if there is a red or purple present in the color column. I'm not sure how to implement this.
Please help