---
title: withColumns
description: "DataFrame.withColumns method in PySpark: Returns a new DataFrame by adding multiple columns or replacing the existing columns that have the same names."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/withColumns
---

# withColumns

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

```python
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|
# +---+-----+----+----+
```
