Search⌘ K
AI Features

fillna() with Pandas Series

Explore how to use the fillna() method with Pandas Series to replace missing data while understanding when it returns a new object versus modifying inplace. Learn about handling various missing value types and the rationale behind the method's design.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.8
import numpy as np
import pandas as pd
s = pd.Series([1, 2, np.nan, 4, 5])
s.fillna(3)
print(s.sum())

Explanation

The pandas.Series.fillna documentation says, that it returns the following:

"Returns: Series or None

Object with missing values ...