snowflake.snowpark.functions.trim

snowflake.snowpark.functions.trim(e: Union[Column, str], trim_string: Optional[Union[Column, str]] = None) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L2311-L2337)

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
语言: 中文