---
title: withColumnsRenamed
description: "DataFrame.withColumnsRenamed method in PySpark: Returns a new DataFrame by renaming multiple columns. This is a no-op if the schema doesn't contain the given column names."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/withColumnsRenamed
---

# withColumnsRenamed

Returns a new DataFrame by renaming multiple columns. This is a no-op if the schema doesn't contain the given column names.

## Syntax

```
withColumnsRenamed(colsMap: Dict[str, str])
```

## Parameters

| Parameter | Type | Description                                                                                                        |
| --------- | ---- | ------------------------------------------------------------------------------------------------------------------ |
| `colsMap` | dict | A dict of existing column names and corresponding desired column names. Currently, only a single map is supported. |

## Returns

`DataFrame`: DataFrame with renamed columns.

## Examples

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

df.withColumnsRenamed({"age": "age2"}).show()
# +----+-----+
# |age2| name|
# +----+-----+
# |   2|Alice|
# |   5|  Bob|
# +----+-----+

df.withColumnsRenamed({"age": "age2", "name": "name2"}).show()
# +----+-----+
# |age2|name2|
# +----+-----+
# |   2|Alice|
# |   5|  Bob|
# +----+-----+

df.withColumnsRenamed({"non_existing": "new_name"}).show()
# +---+-----+
# |age| name|
# +---+-----+
# |  2|Alice|
# |  5|  Bob|
# +---+-----+
```
