fillna() | Teradata Package for Python - fillna() Method - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00
Published
March 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

The fillna() method replaces the null values in a column with the value specified.

Required Argument

value
Specifies the values to replace the null values with. If value is a dict then "columns" is ignored.
To use predefined strings to replace the null value, set "literal_value" to True.
Permitted values: Predefined strings:
  • ''MEAN' - Replace null value with the average of the values in the column.
  • 'MODE' - Replace null value with the mode of the values in the column.
  • 'MEDIAN' - Replace null value with the median of the values in the column.
  • 'MIN' - Replace null value with the minimum of the values in the column.
  • 'MAX' - Replace null value with the maximum of the values in the column.

Types: int, float, str, dict containing column names and value, list

Optional Arguments

columns
Specifies the column names to perform the null value replacement. If "columns" is None, then all the columns having null value and data type similar to the data type of the value specified are considered.

The default value is None.

Types: str, tuple or list of str

literal_value
Specifies whether the pre-defined strings passed to "value" should be treated as literal or not.

The default value is False.

partition_column
Specifies the column name to partition the data.

The default value is None.

Example 1: Populate null value in column 'Jan' and 'Mar' with the value specified as dictionary

>>> load_example_data("dataframe", "sales")
>>> df = DataFrame("sales")
>>> df
accounts Feb Jan Mar Apr datetime
Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
Yellow Inc 90.0 NaN NaN NaN 04/01/2017
Orange Inc 210.0 NaN NaN 250.0 04/01/2017
Red Inc 200.0 150.0 140.0 NaN 04/01/2017
>>> df.fillna({"Jan": 123, "Mar":234})
accounts Feb Jan Mar Apr datetime
0 Blue Inc 90.0 50 95 101.0 17/01/04
1 Alpha Co 210.0 200 215 250.0 17/01/04
2 Jones LLC 200.0 150 140 180.0 17/01/04
3 Yellow Inc 90.0 123 234 NaN 17/01/04
4 Orange Inc 210.0 123 234 250.0 17/01/04
5 Red Inc 200.0 150 140 NaN 17/01/04

Example 2: Populate the null value in 'Jan' column with minimum value in that column

>>> load_example_data("dataframe", "sales")
>>> df = DataFrame("sales")
>>> df
accounts Feb Jan Mar Apr datetime
Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
Yellow Inc 90.0 NaN NaN NaN 04/01/2017
Orange Inc 210.0 NaN NaN 250.0 04/01/2017
Red Inc 200.0 150.0 140.0 NaN 04/01/2017
>>> df.fillna("Min", "Jan")
accounts Feb Jan Mar Apr datetime
0 Yellow Inc 90.0 50 NaN NaN 17/01/04
1 Jones LLC 200.0 150 140.0 180.0 17/01/04
2 Red Inc 200.0 150 140.0 NaN 17/01/04
3 Blue Inc 90.0 50 95.0 101.0 17/01/04
4 Alpha Co 210.0 200 215.0 250.0 17/01/04
5 Orange Inc 210.0 50 NaN 250.0 17/01/04

Example 3: Populate the null value in 'pclass' and 'fare' column with mean value with partition column as 'sex'

>>> load_example_data("teradataml", ["titanic"])
>>> df = DataFrame.from_table("titanic")
>>> df.fillna(value="mean", columns=["pclass", "fare"], partition_column="sex")
passenger survived pclass name sex age sibsp parch ticket fare cabin embarked
120 0 3 Andersson, Miss. Ellis Anna Maria female 2 4 2 347082 31.275 None S
200 0 2 Yrois, Miss. Henriette ("Mrs Harbeck") female 24 0 0 248747 13.0 None S
57 1 2 Rugg, Miss. Emily female 21 0 0 C.A. 31026 10.5 None S
505 1 1 Maioni, Miss. Roberta female 16 0 0 110152 86.5 B79 S
503 0 3 O'Sullivan, Miss. Bridget Mary female None 0 0 330909 7.6292 None Q
360 1 3 Mockler, Miss. Helen Mary "Ellie" female None 0 0 330980 7.8792 None Q
223 0 3 Green, Mr. George Henry male 51 0 0 21440 8.05 None S
345 0 2 Fox, Mr. Stanley Hubert male 36 0 0 229236 13.0 None S
406 0 2 Gale, Mr. Shadrach male 34 1 0 28664 21.0 None S
528 0 1 Farthing, Mr. John male None 0 0 PC 17483 221.7792 C95 S