replace | teradatamlspk | pyspark2teradataml - replace - Teradata Package for Python

Teradata® pyspark2teradataml User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-11
dita:mapPath
oeg1710443196055.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
oeg1710443196055
Product Category
Teradata Vantage

When use the replace function to replace a numeric column with a string type, PySpark and teradataml work differently: PySpark ignores such replacement, but teradataml raises error.

You should mention the value to replace appropriately based on column type.

PySpark

>>> df.na.replace(23.5, 23.0).show()
+---+-------+---------+--------------------+
| id|int_col|float_col|             str_col|
+---+-------+---------+--------------------+
|  1|     21|     21.2|Braund, Mr. Owen ...|
|  2|     22|     22.6|Cumings, Mrs. Joh...|
|  3|     23|     23.0|Palsson, Master. ...|
+---+-------+---------+--------------------+

teradatamlspk

As "str" column is also present, it raises error. You should be careful using columns need to replace.

>>> df.na.replace(23.5, 23.0, 'float_col').show()
+--+-------+---------+--------------------+
|id|int_col|float_col|             str_col|
+--+-------+---------+--------------------+
| 3|     23|     23.0|Palsson, Master. Gos|
| 2|     22|     22.6|Cumings, Mrs. John B|
| 1|     21|     21.2|Braund, Mr. Owen Har|
+--+-------+---------+--------------------+