pyspark.sql.functions.try_to_number(col: ColumnOrName, format: ColumnOrName) → pyspark.sql.column.Column[source]

Convert string ‘col’ to a number based on the string format format. Returns NULL if the string ‘col’ does not match the expected format. The format follows the same semantics as the to_number function.

New in version 3.5.0.

colColumn or str

Input column or strings.

formatColumn or str, optional

format to use to convert number values.


>>> df = spark.createDataFrame([("$78.12",)], ["e"])
>>>, lit("$99.99")).alias('r')).collect()