I have a pandas dataframe that looks like this:
val_1 val_2 Flag
Date
2018-08-27 221.0 121.0 0
2018-08-28 222.0 122.0 1
2018-08-29 223.0 123.0 0
2018-08-30 224.0 124.0 2
2018-08-31 225.0 125.0 0
I want to change the Flag column values to the same values from other columns based on Flag condition. Namely, if Flag is 1 replace 1 with val_1 from the same row and if Flag is 2 replace it with val_2. The output that I am looking would look like this:
val_1 val_2 Flag
Date
2018-08-27 221.0 121.0 0
2018-08-28 222.0 122.0 222.0
2018-08-29 223.0 123.0 0
2018-08-30 224.0 124.0 124.0
2018-08-31 225.0 125.0 0
I know that I can use .loc like this df.loc[df['Flag'] == 1, ['Flag']] =. I don't know what goes to the right hand side of the code.
