snowflake.snowpark.DataFrame.select¶
- DataFrame.select(*cols: Union[Column, str, TableFunctionCall, Iterable[Union[Column, str, TableFunctionCall]]]) DataFrame [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/dataframe.py#L975-L1105)¶
Returns a new DataFrame with the specified Column expressions as output (similar to SELECT in SQL). Only the Columns specified as arguments will be present in the resulting DataFrame.
You can use any
Column
expression or strings for named columns.- Example 1::
>>> df = session.create_dataframe([[1, "some string value", 3, 4]], schema=["col1", "col2", "col3", "col4"]) >>> df_selected = df.select(col("col1"), col("col2").substr(0, 10), df["col3"] + df["col4"])
Example 2:
>>> df_selected = df.select("col1", "col2", "col3")
Example 3:
>>> df_selected = df.select(["col1", "col2", "col3"])
Example 4:
>>> df_selected = df.select(df["col1"], df.col2, df.col("col3"))
Example 5:
>>> from snowflake.snowpark.functions import table_function >>> split_to_table = table_function("split_to_table") >>> df.select(df.col1, split_to_table(df.col2, lit(" ")), df.col("col3")).show() ----------------------------------------------- |"COL1" |"SEQ" |"INDEX" |"VALUE" |"COL3" | ----------------------------------------------- |1 |1 |1 |some |3 | |1 |1 |2 |string |3 | |1 |1 |3 |value |3 | -----------------------------------------------
Note
A TableFunctionCall can be added in select when the dataframe results from another join. This is possible because we know the hierarchy in which the joins are applied.
- Parameters:
*cols – A
Column
,str
,table_function.TableFunctionCall
, or a list of those. Note that at most onetable_function.TableFunctionCall
object is supported within a select call.