Coding Ref

fillna() in Pandas

fillna() in Pandas

The fillna() method in Pandas replaces columns (one or multiple) that contain NA, NaN, and None with a specified value, such as an empty string "".

main.py
import pandas as pd

# 👇️ create a pandas dataframe
df = pd.read_csv("example_data.csv")

# Replace all NA, NaN, and None with an empty string ""
df_clean = df.fillna("")

Syntax

dataframe.fillna(value=None, method=None, axis=None, inplace=False, limit=None, downcast=None)

Parameters

Paramter Value Description
value
Number
String
Dictionary
Series
DataFrame

Required. Specifies the value to replace the NULL values with. This can also be values for the entire row or column.

method
backfill
bfill
pad
ffill</div> <div>None

Optional, default None. Specifies the method to use when replacing

axis
0
1
index
columns
Optional, default 0. The axis to fill the NULL values along
inplace
True
False

Optional, default False. If True: the replacing is done on the current DataFrame. If False: returns a copy where the replacing is done.

limit
Number
None

Optional, default None. Specifies the maximum number of NULL values to fill (if method is specified)

downcase
Dictionary
None
Optional, a dictionary of values to fill for specific data types

Conclusion

The fillna() method in Pandas replaces columns (one or multiple) that contain NA, NaN, and None with a specified value, such as an empty string "".

You'll also like

Related tutorials curated for you

    How to groupby, then sort within groups in Pandas

    How to use applymap() in Pandas

    How to use ffill() in Pandas

    How to normalize a column in Pandas

    How to convert a series to a NumPy array in Pandas

    How to get the first row in Pandas

    fillna() in Pandas

    How to use where() in Pandas

    How to split a Pandas DataFrame by a column value

    How to convert Pandas timestamp to datetime

    How to round in Pandas

    How to convert string to float in Pandas