I am working with a pandas data frame that contains also nan values. I want to substitute the nans with interpolated values with In such a case I want to apply a function on Note that I am aware of the option of So do you know of a function/ do you know how to construct a code that results in my desired output? Tnxdf.interpolate, but only if the length of the sequence of nan values is =print(df)
A B C
1 1 1
nan nan 2
nan nan 3
nan 4 nan
5 5 5
df that only the nan sequences with length N<=2 get filled, but the larger sequences get untouched, resulting in my desired output ofprint(df)
A B C
1 1 1
nan 2 2
nan 3 3
nan 4 4
5 5 5
limit=N inside df.interpolate, but it doesn't fulfil what I want, because it would fill any length of nan sequence, just limit the filling to a the first 3 nans resulting in the undesired outputprint(df)
A B C
1 1 1
2 2 2
3 3 3
nan 4 4
5 5 5