नोट
इस पेज तक पहुँच के लिए प्रमाणन की आवश्यकता होती है. आप साइन इन करने या निर्देशिकाओं को बदलने का प्रयास कर सकते हैं.
इस पेज तक पहुँच के लिए प्रमाणन की आवश्यकता होती है. आप निर्देशिकाओं को बदलने का प्रयास कर सकते हैं.
Returns a new DataFrame by renaming an existing column. This is a no-op if the schema doesn't contain the given column name.
Syntax
withColumnRenamed(existing: str, new: str)
Parameters
| Parameter | Type | Description |
|---|---|---|
existing |
str | The name of the existing column to be renamed. |
new |
str | The new name to be assigned to the column. |
Returns
DataFrame: A new DataFrame with renamed column.
Examples
df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
df.withColumnRenamed("age", "age2").show()
# +----+-----+
# |age2| name|
# +----+-----+
# | 2|Alice|
# | 5| Bob|
# +----+-----+
df.withColumnRenamed("non_existing", "new_name").show()
# +---+-----+
# |age| name|
# +---+-----+
# | 2|Alice|
# | 5| Bob|
# +---+-----+
df.withColumnRenamed("age", "age2").withColumnRenamed("name", "name2").show()
# +----+-----+
# |age2|name2|
# +----+-----+
# | 2|Alice|
# | 5| Bob|
# +----+-----+