Teradata Package for Python Function Reference | 20.00 - zeroifnull - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.zeroifnull = zeroifnull()
- DESCRIPTION:
Function converts the values in column from null to zero to avoid cases where a null result creates an error.
NOTES:
1. If the type of the column is not FLOAT, column values are converted to FLOAT
based on implicit type conversion rules. If the value cannot be converted, an
error is reported. For more information on implicit type conversion,
see Teradata Vantage™ Data Types and Literals.
2. Unsupported column types:
a. BYTE or VARBYTE
b. LOBs (BLOB or CLOB)
c. CHARACTER or VARCHAR if the server character set is GRAPHIC
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
DataFrameColumn
EXAMPLES:
# Load the data to execute the example.
>>> load_example_data("dataframe","admissions_train")
# Create a DataFrame on 'admissions_train' table.
# We will process the data to introduce some null values in the dataframe, which we will convert to 0
# using "zeroifnull()" function.
>>> df = DataFrame('admissions_train')
>>> df1 = df[df.gpa == 4].select(['id', 'stats', 'masters', 'gpa'])
>>> df2 = df[df.gpa < 2].select(['id', 'stats', 'programming', 'admitted'])
# Let's concat both df1 and df2.
>>> cdf = df1.concat(df2)
>>> cdf
stats masters gpa programming admitted
id
29 Novice yes 4.0 None NaN
24 Advanced None NaN Novice 1.0
19 Advanced None NaN Advanced 0.0
15 Advanced yes 4.0 None NaN
13 Advanced no 4.0 None NaN
# Let's persist the cdf to Vantage.
>>> copy_to_sql(cdf, "zeroifnull_test_table")
>>> newdf = DataFrame("zeroifnull_test_table")
>>> newdf
id stats masters gpa programming admitted
0 19 Advanced None NaN Advanced 0.0
1 24 Advanced None NaN Novice 1.0
2 13 Advanced no 4.0 None NaN
3 29 Novice yes 4.0 None NaN
4 15 Advanced yes 4.0 None NaN
# Converting null values in 'admitted' column to 0 using 'zeroifnull()' function.
>>> rdf = newdf.assign(admitted_zero_if_null = newdf.admitted.zeroifnull())
>>> print(rdf)
id stats masters gpa programming admitted admitted_zero_if_null
0 29 Novice yes 4.0 None NaN 0
1 24 Advanced None NaN Novice 1.0 1
2 19 Advanced None NaN Advanced 0.0 0
3 13 Advanced no 4.0 None NaN 0
4 15 Advanced yes 4.0 None NaN 0