I have a dataframe with three columns (timestamp, temperature and waterlevel). What I want to do is to replace all NaN values in the waterlevel column with interpolated values. For example:
The waterlevel value is always decreasing till it is 0. Therefore, the waterlevel cannot be negative. Also, if the waterlevel is staying the same, the interpolated values should also be the same. Ideally, the stepsize between the interpolated values (within two available waterlevel values) should be the same.
What I have tried so far was:
df['waterlevel'].interpolate(method ='linear', limit_direction ='backward') # backwards because the waterlevel value is always decreasing.
This does not work. After executing this line, every NaN value has turned to a 0 with the parameter 'forward' and stays NaN with the parameter 'backward'.
and
df = df['waterlevel'].assign(InterpolateLinear=df.target.interpolate(method='linear'))
Any suggestions on how to solve this?