Sample dataframe as below
df = pd.DataFrame({'ID': ['a', 'a', 'a', 'b', 'b', 'c', 'c'],
'color': ['red', 'blue', 'green', 'red', 'blue', 'red', 'green']})
I want 2 columns with all combinations of the color field after grouping by ID.
I want the resultant dataframe as shown below
ID |
color1 |
color2 |
a |
red |
blue |
a |
red |
green |
a |
blue |
red |
a |
blue |
green |
a |
green |
red |
a |
green |
blue |
b |
red |
blue |
b |
blue |
red |
c |
red |
green |
c |
green |
red |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…