Rename Specific Columns

Use the df.rename() function and refer the columns to be renamed. Not all the columns have to be renamed:

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})

# Or rename the existing DataFrame (rather than creating a copy) 
df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)

Minimal Code Example

df = pd.DataFrame('x', index=range(3), columns=list('abcde'))
df

   a  b  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

The following methods all work and produce the same output:

df2 = df.rename({'a': 'X', 'b': 'Y'}, axis=1)
df2 = df.rename({'a': 'X', 'b': 'Y'}, axis='columns')
df2 = df.rename(columns={'a': 'X', 'b': 'Y'}) 

df2

   X  Y  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

Remember to assign the result back, as the modification is not-inplace. Alternatively, specify inplace=True:

df.rename({'a': 'X', 'b': 'Y'}, axis=1, inplace=True)
df

   X  Y  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x
 

You can specify errors='raise' to raise errors if an invalid column-to-rename is specified.


Reassign Column Headers

Use df.set_axis() with axis=1.

df2 = df.set_axis(['V', 'W', 'X', 'Y', 'Z'], axis=1)
df2

   V  W  X  Y  Z
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

Headers can be assigned directly:

df.columns = ['V', 'W', 'X', 'Y', 'Z']
df

   V  W  X  Y  Z
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x
Answer from lexual on Stack Overflow
Top answer
1 of 16
4717

Rename Specific Columns

Use the df.rename() function and refer the columns to be renamed. Not all the columns have to be renamed:

df = df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'})

# Or rename the existing DataFrame (rather than creating a copy) 
df.rename(columns={'oldName1': 'newName1', 'oldName2': 'newName2'}, inplace=True)

Minimal Code Example

df = pd.DataFrame('x', index=range(3), columns=list('abcde'))
df

   a  b  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

The following methods all work and produce the same output:

df2 = df.rename({'a': 'X', 'b': 'Y'}, axis=1)
df2 = df.rename({'a': 'X', 'b': 'Y'}, axis='columns')
df2 = df.rename(columns={'a': 'X', 'b': 'Y'}) 

df2

   X  Y  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

Remember to assign the result back, as the modification is not-inplace. Alternatively, specify inplace=True:

df.rename({'a': 'X', 'b': 'Y'}, axis=1, inplace=True)
df

   X  Y  c  d  e
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x
 

You can specify errors='raise' to raise errors if an invalid column-to-rename is specified.


Reassign Column Headers

Use df.set_axis() with axis=1.

df2 = df.set_axis(['V', 'W', 'X', 'Y', 'Z'], axis=1)
df2

   V  W  X  Y  Z
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x

Headers can be assigned directly:

df.columns = ['V', 'W', 'X', 'Y', 'Z']
df

   V  W  X  Y  Z
0  x  x  x  x  x
1  x  x  x  x  x
2  x  x  x  x  x
2 of 16
2574

Just assign it to the .columns attribute:

>>> df = pd.DataFrame({'b': [10,20]})
>>> df
   b
0   1  10
1   2  20

>>> df.columns = ['a', 'b']
>>> df
   a   b
0  1  10
1  2  20
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-rename-columns-in-pandas-dataframe
Rename Columns in Pandas DataFrame - GeeksforGeeks
The set_axis method can be used to rename all columns in a DataFrame. This function takes a list of new column names and an axis (0 for rows, 1 for columns) and returns a DataFrame with renamed columns.
Published   October 3, 2025
🌐
Built In
builtin.com › data-science › rename-columns-pandas
How to Rename Columns in Pandas | Built In
More on PandasLoc and iLoc Functions ... can be used to label columns as well as rows. All you need to do is simply pass the list of column names to the .set_axis() function and specify axis = 1 to rename ......
🌐
KDnuggets
kdnuggets.com › 2022 › 11 › 4-ways-rename-pandas-columns.html
4 Ways to Rename Pandas Columns - KDnuggets
Method 1: using rename() function. Method 2: assigning list of new column names. Method 3: replacing the columns string. Method 4: using set_axis() function. We will first create a simple dictionary of student class performance.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-rename-columns-in-pandas-dataframe
How to rename columns in Pandas DataFrame - GeeksforGeeks
The simplest way to rename columns in a Pandas DataFrame is to use the rename() function. This method allows renaming specific columns by passing a dictionary, where keys are the old column names and values are the new column names.
Published   November 12, 2024
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to rename columns with list in pandas
How to Rename Columns With List in Pandas - Spark By {Examples}
July 7, 2025 - If you have all the columns you wanted to rename with a list in pandas DataFrame, you can just assign the list to DataFrame.columns to rename all columns.
Find elsewhere
🌐
Statology
statology.org › home › how to rename columns in pandas (with examples)
How to Rename Columns in Pandas (With Examples)
October 20, 2022 - This tutorial explains how to rename columns in a pandas DataFrame, including several examples.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Rename column/index names of DataFrame | note.nkmk.me
August 7, 2023 - If you want to update the original object, overwrite it like df = df.add_prefix(). To change all names, use the set_axis() method or directly update the columns/index attributes. You can change all column/index names using the set_axis() method ...
🌐
Codedamn
codedamn.com › news › python
How to rename columns in Pandas (with examples included)
March 9, 2024 - This makes rename more suited for partial column name changes. Pandas’ pd.read_csv function provides a convenient way to rename columns as you load your data by using the names parameter along with header=0.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-rename-a-column-in-pandas
How to Rename a Column in Pandas – Python Pandas Dataframe Renaming Tutorial
January 13, 2023 - import pandas as pd students = { "firstname": ["John", "Jane", "Jade"], "lastname": ["Doe", "Done", "Do"] } # convert student names into a Dataframe df = pd.DataFrame(students) df.rename(columns={"firstname": "FIRSTNAME", "lastname": "SURNAME"}, inplace=True) print(df) # Output FIRSTNAME SURNAME 0 John Doe 1 Jane Done 2 Jade Do · You can change just one column name, too. You are not required to change all the column names at the same time.
🌐
DigitalOcean
digitalocean.com › community › tutorials › pandas-rename-column-index
Pandas Rename Column and Index | DigitalOcean
August 4, 2022 - Sometimes we want to rename columns and indexes in the Pandas DataFrame object. We can use pandas DataFrame rename() function to rename columns and indexes.
🌐
Career Karma
careerkarma.com › blog › python › rename column in pandas: a beginner’s guide
Rename Column in Pandas: A Beginner’s Guide | Career Karma
December 1, 2023 - You rename all the columns in a Pandas dataframe by assigning the “columns” attribute a list of new column headings.
🌐
PYnative
pynative.com › home › python › pandas › rename columns in pandas dataframe
Rename columns in Pandas DataFrame
March 9, 2023 - Use the axis parameter of a df.rename() to rename columns and row index. The axis can be a row or column. The column axis represented as 1 or ‘columns’. Set axis=1 and pass column names you want to rename as a dictionary (Key-Value pairs).
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › rename
Python Pandas DataFrame rename() - Rename Columns or Index | Vultr Docs
April 10, 2025 - Here, only column names starting with 'S' are prefixed with 'Grade_'. Pandas' rename() method offers a robust framework for renaming DataFrame columns and indices dynamically and efficiently.
🌐
PythonHow
pythonhow.com › how › rename-column-names-with-pandas
Here is how to rename column names with Pandas in Python
The resulting DataFrame will have the new column names. You can also use the inplace parameter of the rename() method to modify the DataFrame in place, without assigning the result to a new variable. Here is an example: import pandas as pd # create a sample DataFrame df = pd.DataFrame({ "A": ...
🌐
ListenData
listendata.com › home › pandas
How to rename columns in Pandas Dataframe
2 Methods to rename columns in Pandas In Pandas there are two simple methods to rename name of columns.
🌐
Kanaries
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in Python – Kanaries
February 10, 2026 - The rename() method handles most column renaming tasks -- pass a dictionary for specific columns or a function for bulk transformations. When you need to replace all column names at once, assign a list to df.columns or use set_axis().
🌐
MungingData
mungingdata.com › pandas › rename-columns
Renaming Columns in Pandas DataFrames - MungingData
Write a function that'll replace all the spaces with underscores in the column names. df.rename(lambda x: x.replace(" ", "_"), axis="columns", inplace=True) print(df) some_place fun_activity 0 hawaii surfing 1 costa rica zip lining · Stick to the column renaming methods mentioned in this post and don't use the techniques that were popular in earlier versions of Pandas.