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
Discussions

Most efficient way to rename multiple, pre-defined columns in a pandas dataframe
If your dict is a mapping of old -> new you can pass it directly. >>> df A B C D 0 1 2 3 4 >>> dimension_names {'B': 'NONO C', 'C': 'BONO C', 'D': 'HIHI D'} >>> df.rename(columns=dimension_names) A NONO C BONO C HIHI D 0 1 2 3 4 More on reddit.com
🌐 r/learnpython
4
1
December 18, 2021
How to rename column values in pandas
I'm on my phone, but I think you're looking for replace. df['Column_1'] = df['Column_1'].str.replace('x','y') More on reddit.com
🌐 r/learnpython
7
5
May 10, 2016
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
Is there any way to reorder, rename, and drop multiple pandas columns in one go?
For the first part, you could use a dictionary. keeps={ 'date':'date', 'region':'region', 'state':'state', 'cases':'cases_daily', 'conf_cases':'cases_todate', 'deaths':'deaths_daily', 'tot_death':'deaths_total', 'consent_cases':'consent_cases', 'consent_deaths':'consent_deaths' } data=data[keeps.keys()].rename(keeps,axis=1) You're out of luck with your description I think but I also can't see a use for it. Python/pandas is about processing data not storing it. If the columns need to be documented that can be done in a csv, a wiki or code comments depending on your environment not made part of the actual code. More on reddit.com
🌐 r/learnpython
3
4
November 18, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-rename-columns-in-pandas-dataframe
Rename Columns in Pandas DataFrame - GeeksforGeeks
The rename() function allows renaming specific columns by passing a dictionary, where keys are the old column names and values are the new column names.
Published: October 3, 2025
🌐
DataCamp
datacamp.com › tutorial › pandas-rename-columns
Pandas Rename Column: A Complete Python Guide With Examples | DataCamp
August 17, 2026 - Learn how to rename columns in pandas with .rename(), df.columns, and .set_axis(), plus Python functions for snake_case and fixes for KeyError and ValueError.
🌐
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 columns parameter.
🌐
YouTube
youtube.com › watch
Rename columns in pandas // Change the name of Python ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Find elsewhere
🌐
Kamatera
kamatera.com › home › knowledgebase › how to rename columns in pandas dataframes
How to Rename Columns in Pandas DataFrames | Kamatera
September 21, 2025 - When you need to rename all columns at once, directly assigning a new list to the · DataFrame’s columns attribute is often the most straightforward approach. This method is particularly useful for complete schema changes or when importing data with meaningless column headers. ... When using this method, the length of the new column list must exactly match the number of columns in your DataFrame. If there’s a mismatch, pandas will raise a ValueError.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.1 › reference › api › pandas.DataFrame.rename.html
pandas.DataFrame.rename — pandas 2.1.4 documentation
Can be either the axis name (‘index’, ‘columns’) or number (0, 1). The default is ‘index’. ... Also copy underlying data. ... Whether to modify the DataFrame rather than creating a new one. If True then value of copy is ignored. ... In case of a MultiIndex, only rename labels in the specified level.
🌐
Medium
medium.com › @amit25173 › pandas-how-to-rename-columns-c3a49d204301
Pandas How to Rename Columns. The biggest lie in data science? That… | by Amit Yadav | Medium
April 12, 2025 - This flexibility is what makes Pandas powerful for data analysis. Why does column naming matter? Simple: good names can make your data self-explanatory. For example, instead of labeling a column “A,” calling it “Sales_Amount” provides much more context. Now that we’ve set the stage, let’s look at the different ways to rename these columns!
🌐
GeeksforGeeks
geeksforgeeks.org › python › rename-column-by-index-in-pandas
Rename Column by Index in Pandas - GeeksforGeeks
Just by the use of the index, a column can be renamed. Dealing with large and complex datasets in Pandas often requires manipulating column names for better analysis. Renaming columns by their index position can be an efficient and straightforward way to achieve this.
Published: October 11, 2025
🌐
YouTube
youtube.com › watch
Pandas Change Column Names | Pandas.DataFrame.rename() - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2026 Google LLC
Published: September 3, 2020
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Rename column/index names of DataFrame | note.nkmk.me
August 7, 2023 - You can rename (change) column and/or index names in a pandas.DataFrame by using the rename(), add_prefix(), add_suffix(), set_axis() methods or by directly updating the columns and/or index attributes.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.5 › reference › api › pandas.DataFrame.rename.html
pandas.DataFrame.rename — pandas 1.5.3 documentation
Can be either the axis name (‘index’, ‘columns’) or number (0, 1). The default is ‘index’. ... Also copy underlying data. ... Whether to modify the DataFrame rather than creating a new one. If True then value of copy is ignored. ... In case of a MultiIndex, only rename labels in the specified level.
🌐
YouTube
youtube.com › watch
Change Pandas Dataframe Column Names - YouTube
Welcome to Interactive Training! In this session, we'll take a look at how to change column names in a Pandas DataFrame. Whether you're preparing your data f...
Published: October 25, 2024
🌐
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.
🌐
Medium
medium.com › data-oriented-programming-tips › two-reasons-your-column-renaming-does-not-work-in-pandas-c5f40ecf04aa
Two reasons your column renaming does not work in Pandas | by Danferno | Data Oriented Programming Tips | Medium
August 21, 2023 - That means you need to explicitly specify that you want to rename the columns. import pandas as pd df = pd.DataFrame(data=[0,1,2], columns=['A']) # Works df = df.rename(columns={'A':'B'}) print(df.columns) # Index(['B'], dtype='object') Yay
🌐
PYnative
pynative.com › home › python › pandas › rename columns in pandas dataframe
Rename columns in Pandas DataFrame
March 9, 2023 - Suppose we have a list of column names that we need to use to rename the existing DataFrame. In that case, we can pass the list of column labels to a DataFrame.columns attributes as shown in the below example. It will replace the existing names with the new names in the order you provide. import pandas as pd student_dict = {"name": ["Joe", "Nat", "Harry"], "age": [20, 21, 19], "marks": [85.10, 77.80, 91.54]} student_df = pd.DataFrame(student_dict) # before rename print(student_df.columns.values) # rename column with list student_df.columns = ['stud_name', 'stud_age', 'stud_marks'] # after rename print(student_df.columns.values)Code language: Python (python) Run
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.rename.html
pandas.Series.rename — pandas 3.0.6 documentation
>>> s = pd.Series([1, 2, 3]) >>> s 0 1 1 2 2 3 dtype: int64 >>> s.rename("my_name") # scalar, changes Series.name 0 1 1 2 2 3 Name: my_name, dtype: int64 >>> s.rename(lambda x: x**2) # function, changes labels 0 1 1 2 4 3 dtype: int64 >>> s.rename({1: 3, 2: 5}) # mapping, changes labels 0 1 3 2 5 3 dtype: int64
🌐
MungingData
mungingdata.com › pandas › rename-columns
Renaming Columns in Pandas DataFrames - MungingData
This article explains how to rename a single or multiple columns in a Pandas DataFrame.