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.
Returns a new DataFrame by adding multiple columns or replacing the existing columns that have the same names.
Syntax
withColumns(*colsMap: Dict[str, Column])
Parameters
| Parameter | Type | Description |
|---|---|---|
colsMap |
dict | a dict of column name and Column. Currently, only a single map is supported. |
Returns
DataFrame: DataFrame with new or replaced columns.
Examples
df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
df.withColumns({'age2': df.age + 2, 'age3': df.age + 3}).show()
# +---+-----+----+----+
# |age| name|age2|age3|
# +---+-----+----+----+
# | 2|Alice| 4| 5|
# | 5| Bob| 7| 8|
# +---+-----+----+----+