# Rename columns in a Python Pandas DataFrame

**URL:** https://sentry.io/answers/rename-columns-in-a-python-pandas-dataframe/

---

## The Problem

How do I rename the columns in a Python Pandas DataFrame?

## The Solution

You can use the [`DataFrame.rename()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html) method to rename columns. Assign the result back to the same variable to apply the change:

```python
my_dataframe = my_dataframe.rename(columns={'old_column': 'new_column', 'old_column2': 'new_column2'})
```

Any columns not renamed will retain their existing names.

---

*Source: [sentry.io/answers/rename-columns-in-a-python-pandas-dataframe/](https://sentry.io/answers/rename-columns-in-a-python-pandas-dataframe/)*
