Skip to main content

select

Projects a set of expressions and returns a new DataFrame.

Syntax​

select(*cols: "ColumnOrName")

Parameters​

Parameter

Type

Description

cols

str, Column, or list

column names (string) or expressions (Column). If one of the column names is '*', that column is expanded to include all columns in the current DataFrame.

Parameter

Type

Description

cols

str, Column, or list

column names (string) or expressions (Column). If one of the column names is '*', that column is expanded to include all columns in the current DataFrame.

Returns​

DataFrame: A DataFrame with subset (or all) of columns.

Examples​

Python
df = spark.createDataFrame([
(2, "Alice"), (5, "Bob")], schema=["age", "name"])

df.select('*').show()
# +---+-----+
# |age| name|
# +---+-----+
# | 2|Alice|
# | 5| Bob|
# +---+-----+

df.select(df.name, (df.age + 10).alias('age')).show()
# +-----+---+
# | name|age|
# +-----+---+
# |Alice| 12|
# | Bob| 15|
# +-----+---+