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

snowflake.snowpark.DataFrame.rename

DataFrame.rename(col_or_mapper: Union[Column, str, dict], new_column: str = None)[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/dataframe.py#L3645-L3715)

Returns a DataFrame with the specified column col_or_mapper renamed as new_column. If col_or_mapper is a dictionary, multiple columns will be renamed in the returned DataFrame.

Example::
>>> # This example renames the column `A` as `NEW_A` in the DataFrame.
>>> df = session.sql("select 1 as A, 2 as B")
>>> df_renamed = df.rename(col("A"), "NEW_A")
>>> df_renamed.show()
-----------------
|"NEW_A"  |"B"  |
-----------------
|1        |2    |
-----------------

>>> # This example renames the column `A` as `NEW_A` and `B` as `NEW_B` in the DataFrame.
>>> df = session.sql("select 1 as A, 2 as B")
>>> df_renamed = df.rename({col("A"): "NEW_A", "B":"NEW_B"})
>>> df_renamed.show()
---------------------
|"NEW_A"  |"NEW_B"  |
---------------------
|1        |2        |
---------------------
Copy
Parameters:
  • col_or_mapper – The old column instance or column name to be renamed, or the dictionary mapping from column instances or columns names to their new names (string)

  • new_column – The new column name (string value), if a single old column is given

Language: English