I think you can do a self merge and query:
df.merge(df, on='ID', suffixes=[1,2]).query('color1 != color2')
Or similar, merge then filter:
(df.merge(df, on='ID', suffixes=[1,2])
.loc[lambda x: x['color1'] != x['color2']]
)
Output:
ID color1 color2
1 a red blue
2 a red green
3 a blue red
5 a blue green
6 a green red
7 a green blue
10 b red blue
11 b blue red
14 c red green
15 c green red
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…