Skip to content
Advertisement

pd Fill NAN with increasing incremental Value python

Hi I am trying to do an incremental increase on the data I have for NaN values for example:

Day Reding
1 NaN
2 2.5
3 NaN
4 NaN
5 NaN
6 3.9
7 NaN
8 3.4

To this:

Day Reading
1 2.5
2 2.5
3 2.85
4 3.2
5 3.55
6 3.9
7 3.65
8 3.4

Advertisement

Answer

As Pranav mentioned, you can try using interpolation

from cmath import nan
import pandas

dataframe = pandas.DataFrame({'Day': list(range(1,8+1)), 'Reding': [nan, 2.5, nan, nan, nan, 3.9, nan, 3.4]})
dataframe.Reding = dataframe.Reding.interpolate()
print(dataframe)

Output

   Day  Reding
0    1     NaN
1    2    2.50
2    3    2.85
3    4    3.20
4    5    3.55
5    6    3.90
6    7    3.65
7    8    3.40
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement