I am a beginner and would appreciate some help :) I want to reduce the amount of rows by combining rows based on a variable.
I have given data set:
d = {
'day': ['one', 'one', 'two', 'three', 'three'],
'switch': [0, 1, 0, 1, 0 ],
'value': ['green', 'red', 'blue', 'orange', 'purple']
}
df = pd.DataFrame(data=d)
print(df)
day switch value
0 one 0 green
1 one 1 red
2 two 0 blue
3 three 1 orange
4 three 0 purple
I try to restructure the data set to look like this:
day switch_0_value switch_1_value
0 one green red
1 two blue NAN
2 three purple orange
I have looked at 'combine_first' but don't know how to apply that within a loop.
Thank you so much in advance!