You can use pandas methods where
and mask
:
df['color'] = 'green'
df['color'] = df['color'].where(df['Set']=='Z', other='red')
# Replace values where the condition is False
or
df['color'] = 'red'
df['color'] = df['color'].mask(df['Set']=='Z', other='green')
# Replace values where the condition is True
Output:
Type Set color
1 A Z green
2 B Z green
3 B X red
4 C Y red