0

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.

CIHAnalytics
  • 143
  • 1
  • 10
  • Presumably all your columns are numeric, not string, or mixed string and numeric. (Because if they were string, you could use `df.map()`; see [Remap values in pandas column with a dict, preserve NaNs](https://stackoverflow.com/questions/20250771/remap-values-in-pandas-column-with-a-dict-preserve-nans)) – smci Nov 09 '21 at 05:32

1 Answers1

2

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
BENY
  • 317,841
  • 20
  • 164
  • 234