Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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. |
Returns
DataFrame: A DataFrame with subset (or all) of columns.
Examples
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|
# +-----+---+