I have the following Dataframe:
position a_0 a_1 a_2 a_3 a_4 new_value
2 10 13 100
3 12 16 13 120
2 14 12 140
4 15 11 16 16 150
I would like to create the following:
position a_0 a_1 a_2 a_3 a_4 new_value
2 10 13 100 100
3 12 16 13 120 120
2 14 12 140 140
4 15 11 16 16 150 150
Essentially, set each row at index position
to be equal to new_value
.
Ideally without using a for loop.
The difficulty is referring to a different column to set a value for each row. The only idea I've had is to break up the original dataframe into smaller dataframes (based on the value of position
) and then just use the apply
function.
Any other ideas would be super helpful!
Thanks