You are viewing documentation about an older version (1.13.0). View latest version

snowflake.snowpark.functions.trim¶

snowflake.snowpark.functions.trim(e: Union[Column, str], trim_string: Optional[Union[Column, str]] = None) → Column[source]¶

Removes leading and trailing characters from a string. Per default only whitespace ‘ ‘ characters are removed.

Example:

>>> df = session.create_dataframe(['hello', ' world', '   !   '], schema=["a"])
>>> df.collect()
[Row(A='hello'), Row(A=' world'), Row(A='   !   ')]
>>> df.select(trim(col("a"))).collect()
[Row(TRIM("A")='hello'), Row(TRIM("A")='world'), Row(TRIM("A")='!')]
Copy

Example:

>>> df = session.create_dataframe(['EUR 12.96', '7.89USD', '5.99E'], schema=["a"])
>>> df.select(trim(col("a"), lit("EURUSD ")).as_("ans")).collect()
[Row(ANS='12.96'), Row(ANS='7.89'), Row(ANS='5.99')]
Copy

Example:

>>> df = session.create_dataframe(['abc12 45a 79bc!'], schema=["a"])
>>> df.select(trim(col("a"), lit("abc!")).as_("ans")).collect()
[Row(ANS='12 45a 79')]
Copy