I am trying to fill the missing data in my pandas data frame. However this data can only be filled in a certain non-traditional way. First I've marked missing data with -1, so what i want is to replace value of -1 in a certain way.
Column A | Column B |
---|---|
12 | 11 |
99 | -1 |
43 | 34 |
23 | -1 |
65 | -1 |
17 | 42 |
12 | 66 |
99 | -1 |
43 | 22 |
23 | -1 |
65 | -1 |
17 | 42 |
I want to replace every missing value or -1 with next available positive value from the same column.
Column A | Column B |
---|---|
12 | 11 |
99 | 34 |
43 | 34 |
23 | 42 |
65 | 42 |
17 | 42 |
12 | 66 |
99 | 22 |
43 | 22 |
23 | 42 |
65 | 42 |
17 | 42 |
I am able to attain the desired output if number of continuous -1s remain constant using df['col].shift(1)
however that won't work because here placement of -1s are random.
Data size i am dealing with is fairly large.