In [2]:
df
Out[2]:
a
b
c
i
1
7.0
NaN
7.0
2
NaN
6.0
3.0
3
4.0
4.0
NaN
4
8.0
NaN
5.0
5
1.0
4.0
4.0
6
5.0
NaN
NaN
7
7.0
6.0
3.0
8
NaN
6.0
6.0
Replace NA values with a value.
¶
In [3]:
df
.
fillna
(
999
)
Out[3]:
a
b
c
i
1
7.0
999.0
7.0
2
999.0
6.0
3.0
3
4.0
4.0
999.0
4
8.0
999.0
5.0
5
1.0
4.0
4.0
6
5.0
999.0
999.0
7
7.0
6.0
3.0
8
999.0
6.0
6.0
Fill gaps forward
¶
In [4]:
df
.
fillna
(
method
=
'ffill'
)
Out[4]:
a
b
c
i
1
7.0
NaN
7.0
2
7.0
6.0
3.0
3
4.0
4.0
3.0
4
8.0
4.0
5.0
5
1.0
4.0
4.0
6
5.0
4.0
4.0
7
7.0
6.0
3.0
8
7.0
6.0
6.0
Fill gaps backwards.
¶
In [5]:
df
.
fillna
(
method
=
'bfill'
)
Out[5]:
a
b
c
i
1
7.0
6.0
7.0
2
4.0
6.0
3.0
3
4.0
4.0
5.0
4
8.0
4.0
5.0
5
1.0
4.0
4.0
6
5.0
6.0
3.0
7
7.0
6.0
3.0
8
NaN
6.0
6.0