Suppose I have a dataframe with a column as follows:
JavaScript
x
7
1
Column
2
10
3
NaN
4
20
5
NaN
6
30
7
I want each row to be filled in with increments of 5 so that the final output would appear like:
JavaScript
1
7
1
Column
2
10
3
15
4
20
5
25
6
30
7
I’ve tried using np.arange
and .reindex()
but haven’t had much luck. I’m looking for an iterative approach instead of simply manually filling in. Can anyone please help with this?
Advertisement
Answer
Try with interpolate
JavaScript
1
9
1
df['Column']=df.Column.interpolate()
2
Out[86]:
3
0 10.0
4
1 15.0
5
2 20.0
6
3 25.0
7
4 30.0
8
Name: Column, dtype: float64
9