Tsallaka zuwa abun ciki
Justice Tech School

Fill Missing Values

fillna replaces missing values with a constant, a column statistic or a previous value (ffill).

Example
import pandas as pd
import numpy as np
s = pd.Series([1.0, np.nan, 3.0, np.nan])
print(s.fillna(0).tolist())
print(s.fillna(s.mean()).tolist())
print(s.ffill().tolist())

Result

[1.0, 0.0, 3.0, 0.0]
[1.0, 2.0, 3.0, 2.0]
[1.0, 1.0, 3.0, 3.0]

Exercise

Fill with zero.

s.(0)

Quiz Test

What does ffill do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.