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
JavaScript
x
7
1
from cmath import nan
2
import pandas
3
4
dataframe = pandas.DataFrame({'Day': list(range(1,8+1)), 'Reding': [nan, 2.5, nan, nan, nan, 3.9, nan, 3.4]})
5
dataframe.Reding = dataframe.Reding.interpolate()
6
print(dataframe)
7
Output
JavaScript
1
10
10
1
Day Reding
2
0 1 NaN
3
1 2 2.50
4
2 3 2.85
5
3 4 3.20
6
4 5 3.55
7
5 6 3.90
8
6 7 3.65
9
7 8 3.40
10