I have a dataframe where I want to replace all values of 999999 with another column value, while leaving all other values alone. Here is an example of what I have now:
Account | max val | Biology | Statistics |
---|---|---|---|
Bill | 100 | 999999 | 200 |
Frank | 150 | 150 | 999999 |
Wendy | 90 | 999999 | 100 |
Here is what I want the dataframe to look like:
Account | max val | Biology | Statistics |
---|---|---|---|
Bill | 100 | 100 | 200 |
Frank | 150 | 150 | 150 |
Wendy | 90 | 90 | 100 |
Is there an efficient way to accomplish this?
Thanks in advance.
CodePudding user response:
I will do
df = df.mask(df==999999).ffill(axis = 1)
Account max val Biology Statistics
0 Bill 100 100 200.0
1 Frank 150 150.0 150.0
2 Wendy 90 90 100.0