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 11
4718

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 11
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
import pandas as pd df = ... ... Returns new DataFrames with updated column names. Use df.columns.str.replace() to replace unwanted characters in column names....
Published: October 3, 2025
Discussions

How to replace column names with Pandas?
Loop through the header’s index. Within your loop, insert a conditional statement. Your loop could look something like this i = 1 For name in df.indexname loop: while i in range(highest number present in index): if str(i) in name: name.strip(i, ‘.’) The above syntax may not be perfect as I’m still learning myself. However, the logic will achieve your desired result. It looks like pandas added the numbers so the columns wouldn’t be duplicated. If they were duplicated then it wouldn’t be able to differentiate which year your wanting when you access df[‘February’]. You probably could set an option where the headers are indexed by a number and not the incoming value. If you continue to struggle just lmk! I’d be willing to help you see this problem through :) More on reddit.com
🌐 r/learnpython
10
8
January 2, 2022
How do I rename columns if they begin with a phrase
Post your code More on reddit.com
🌐 r/learnpython
12
2
July 26, 2023
Pandas Rename Column does not work
The first and second third methods should work, being the first the straightforward solution. I can't reproduce your problem. You are probably doing something else that you aren't telling us. >>> df1 = df.copy() >>> df.columns Index(['X', 'Filing Date', 'Trade Date', 'Ticker', 'Company Name', 'Insider Name', 'Title', 'Trade Type', 'Price', 'Qty', 'Owned', 'ΔOwn', 'Value'], dtype='object') >>> df.columns = df.columns.str.replace(" ","_") >>> df.columns Index(['X', 'Filing_Date', 'Trade_Date', 'Ticker', 'Company_Name', 'Insider_Name', 'Title', 'Trade_Type', 'Price', 'Qty', 'Owned', 'ΔOwn', 'Value'], dtype='object') >>> df1.rename({"Filing Date": "Filing_Date"}, axis=1, inplace=True) >>> df1.columns Index(['X', 'Filing_Date', 'Trade Date', 'Ticker', 'Company Name', 'Insider Name', 'Title', 'Trade Type', 'Price', 'Qty', 'Owned', 'ΔOwn', 'Value'], dtype='object') More on reddit.com
🌐 r/learnpython
6
1
October 6, 2021
Renaming multiple column headers with nan value [Pandas]
Simply re-assign a new value for columns to your dataframe. Columns for a sample dataframe, obtained by: df.columns yields: Index(['Unnamed: 0', 'first_name', 'last_name', 'company_name', 'address', 'city', 'county', 'postal', 'phone1', 'phone2', 'email', 'web'], dtype='object') I want to rename all of these columns for a simple contrived cases: df.columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'] and now df.columns yields: Index(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'], dtype='object') More on reddit.com
🌐 r/learnpython
9
2
October 4, 2020
People also ask

How do I rename a single column in pandas?
Use df.rename(columns={'old_name': 'new_name'}). This returns a new DataFrame with the specified column renamed. All other columns remain unchanged.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in ...
How do I rename all columns in a pandas DataFrame?
Assign a list directly: df.columns = ['col_a', 'col_b', 'col_c']. The list must have exactly the same number of elements as the DataFrame has columns. Alternatively, use df.set_axis(['col_a', 'col_b', 'col_c'], axis=1) to return a new DataFrame.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in ...
How do I make all column names lowercase in pandas?
Use a list comprehension: df.columns = [col.lower() for col in df.columns]. For additional cleanup like replacing spaces, extend it: df.columns = [col.lower().replace(' ', '_') for col in df.columns].
🌐
docs.kanaries.net
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in ...
🌐
Reddit
reddit.com › r/learnpython › how to replace column names with pandas?
r/learnpython on Reddit: How to replace column names with Pandas?
January 2, 2022 -

I'm working on a very large dataset (from an Excel document) that has the price information of 415 different products for each month since January 2003. For example, when you open the Excel document the first six months look like below.

2003 2003 2003 2003 2003 2003

January February March April May June

When I used the read_excel() method with the header parameter as follows df.read_excel(header=5), the months in 2004 are read as January.1, February.1 etc. Similarly headers for 2005 look like January.2, February.2 and so on.

When I was using a small portion of the data I just created a dictionary for the old headers as keys and new headers as values and used products.rename(columns=dict_name) but now I want to work on the whole document, which has more than 200 headers but I don't want to rename them individually.

I was wondering if there is an easy way to rename all headers with something like find and replace all that includes ".1" for 2004 for example. so that they reflect their respective years along with the months.

I tried to explain the best I could and hope I could explain what I have in my mind.

🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Rename column/index names of DataFrame | note.nkmk.me
August 7, 2023 - The columns argument is used for changing column names, and the index argument is used for changing index names. If you want to change either, you should specify only one of columns or index.
🌐
Anyamemensah
anyamemensah.com › blog › renaming-python
Renaming Columns in Python — Analytics Made Accessible
September 13, 2025 - To replace some or all of the column names, you can use a dictionary with old column names as keys and new column names as values and then pass this dictionary to the mapping parameter.
Find elsewhere
🌐
Kanaries
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in Python – Kanaries
February 10, 2026 - Learn how to rename columns in a pandas DataFrame using rename(), df.columns, set_axis(), list comprehension, and more. Includes a method comparison table, real-world examples, and performance tips.
🌐
Statology
statology.org › home › how to rename columns in pandas (with examples)
How to Rename Columns in Pandas (With Examples)
October 20, 2022 - The following code shows how to replace a specific character in each column name: import pandas as pd #define DataFrame df = pd.DataFrame({'$team':['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'], '$points': [25, 12, 15, 14, 19, 23, 25, 29], '$assists': [5, 7, 7, 9, 12, 9, 9, 4], '$rebounds': [11, 8, 10, 6, 6, 5, 9, 12]}) #list column names list(df) ['team', 'points', 'assists', 'rebounds'] #rename $ with blank in every column name df.columns = df.columns.str.replace('$', '') #view updated list of column names list(df) ['team', 'points', 'assists', 'rebounds']
🌐
KDnuggets
kdnuggets.com › 2022 › 11 › 4-ways-rename-pandas-columns.html
4 Ways to Rename Pandas Columns - KDnuggets
For multiple columns, we just have to provide dictionaries of old and new column names separated by a comma “,” and it will automatically replace the column names.
🌐
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
🌐
DataCamp
datacamp.com › tutorial › pandas-rename-columns
Pandas Rename Column: A Complete Python Guide With Examples | DataCamp
August 17, 2026 - For a deeper look at the loading dataset options, I’d recommend the pandas read_csv() tutorial. One caveat: This is an all-or-nothing approach. The names parameter replaces every column name, so the list length must match the number of columns in the file exactly.
🌐
DigitalOcean
digitalocean.com › community › tutorials › pandas-rename-column-index
Pandas Rename Column and Index | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
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 - In the example above, we put the new column names in a List and assigned it to the Dataframe columns: df.columns = ["FIRSTNAME", "SURNAME"]. This will override the previous column names.
🌐
Stack Abuse
stackabuse.com › bytes › rename-column-names-in-pandas-dataframe
Rename Column Name(s) in Pandas DataFrame
July 5, 2022 - df = df.rename(columns={'Short col name': 'col1', 'Really long column name': 'col2'}) print(df) ... No spam ever. Unsubscribe anytime. Read our Privacy Policy. Note: You don't need to provide every column here - we've totally skipped col3 because it already follows our mock convention.
🌐
Vultr Docs
docs.vultr.com › python › third party › pandas › dataframe › rename()
Python Pandas DataFrame rename()
April 10, 2025 - This method effectively shows how to rename a column in pandas using df.rename columns. Continue using the existing DataFrame. Apply the rename() method with a dictionary that maps existing column names to new names in pandas DataFrame.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pandas-rename-column
Pandas Rename Column - GeeksforGeeks
July 23, 2025 - In this case, all column names are converted to uppercase. This method is highly customizable and allows us to apply conditions like removing spaces, changing the case, or applying regular expressions. If we need to replace specific characters or patterns in column names, we can use str.replace().
🌐
Built In
builtin.com › data-science › rename-columns-pandas
How to Rename Columns in Pandas | Built In
I’m going to demonstrate the four best methods to easily change the Pandas DataFrame column names.
🌐
Medium
medium.com › @python-javascript-php-html-css › renaming-columns-in-a-pandas-dataframe-20caba95830a
Renaming the Columns in a Pandas DataFrame
August 24, 2024 - In the first script, we start by importing the Pandas library with import pandas as pd. Next, we create a DataFrame using pd.DataFrame() with columns labeled as ‘$a’, ‘$b’, ‘$c’, ‘$d’, and ‘$e’. To rename these columns, we directly set the DataFrame’s columns attribute to the new column names [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]. Finally, we display the updated DataFrame using print(df), which shows the new column names.
🌐
RS Blog
reneshbedre.com › blog › rename-column-names-pandas.html
Simple ways to rename column names in pandas DataFrame
October 9, 2022 - Similarly, you can also dfply package to rename the specific columns. dfply Python package is similar to R’s dplyr and supports the data manipulation with pipes on pandas DataFrame. from dfply import * # rename columns # argument should be new column and parameter is old column name df >> rename(first_name='name', height_feet='height')
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to change column name in pandas
How to Change Column Name in Pandas - Spark By {Examples}
March 27, 2024 - You can change the column name of Pandas DataFrame by using the DataFrame.rename() method and the DataFrame.columns() method. In this article, I will