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
4715

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
🌐
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. If you are unfamiliar with dictionaries and are a Python programmer/developer, I encourage you to learn more about them by reading through the · dictionaries documentation . They are powerful and useful tools that can help you solve a wide range of problems. Here's one way to implement a dictionary solution using Pandas: ### import library import pandas as pd ### Set up ## codebook # load codebook fruit_names_cb = pd.read_csv("fruit_codebook.csv") # create dictionary: keys are old names, values are new names fruit_names_dict = dict(zip(fruit_names_cb['old_name'], fruit_names_cb['new_name']))
Discussions

python - How to change column names in pandas Dataframe using a list of names? - Stack Overflow
I have been trying to change the column names of a pandas dataframe using a list of names. The following code is being used: df.rename(columns = list_of_names, inplace=True) However I got a Type E... More on stackoverflow.com
🌐 stackoverflow.com
python - Change column names in Pandas Dataframe from a list - Stack Overflow
My original data set has 100 columns and I did not want to do it manually for each column. I was trying the following using df.rename but keep getting errors. Thanks! ... Sign up to request clarification or add additional context in comments. ... Using rename is a formally more correct approach. You just have to provide a dictionary that maps your current columns names ... More on stackoverflow.com
🌐 stackoverflow.com
In pandas, when should I use column names as attributes and when to use them as indexes?
I thought Pandas was deprecating attribute-style access and wants everyone to use index-style access. Can't remember why I think that, but I think it's a good practice never to refer to attributes that aren't declared somewhere in code. If the layout comes from external data (as it does when you load a dataframe) then you should use string indexes. More on reddit.com
🌐 r/learnpython
5
4
January 1, 2022
How to add a header row above the column names in pandas
df.columns =['Name', 'Code', 'Age', 'Weight'] More on reddit.com
🌐 r/learnpython
10
0
April 12, 2023
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › add-column-names-to-dataframe-in-pandas
Add column names to dataframe in Pandas - GeeksforGeeks
July 15, 2025 - While assign() is typically used for adding new columns to a DataFrame, you can also use it to add columns with meaningful names. This method returns a new DataFrame with the additional columns. ... Player Alias Years Points Experience 0 Amar Alpha 23 69 5 1 Barsha Bravo 25 54 3 2 Carlos Charlie 22 73 4 3 Tanmay Tango 27 70 6 4 Misbah Mike 29 74 2 · If you want to add a prefix or suffix to every column name, you can use the add_prefix() and add_suffix() methods.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-rename-columns-in-pandas-dataframe
Rename Columns in Pandas DataFrame - GeeksforGeeks
Assign a new list of names to df.columns. Ensure the list length matches the number of columns. Print df to verify the updated column names. The set_axis method can be used to rename all columns in a DataFrame.
Published   October 3, 2025
🌐
Kanaries
docs.kanaries.net › topics › Pandas › pandas-rename-column
Pandas Rename Column: 6 Methods to Rename DataFrame Columns in Python – Kanaries
February 10, 2026 - Pandas Merge DataFrames -- merge requires matching column names across DataFrames · Read CSV Files in Pandas -- set column names at import time with names=
🌐
Analytics Vidhya
analyticsvidhya.com › home › renaming column names in pandas
Renaming Column Names in Pandas
December 20, 2023 - The rename() function in Pandas allows us to rename column names by providing a dictionary-like object or a mapping function. We can specify the old column name as the key and the new column name as the value in the dictionary.
🌐
KDnuggets
kdnuggets.com › 2022 › 11 › 4-ways-rename-pandas-columns.html
4 Ways to Rename Pandas Columns - KDnuggets
November 7, 2022 - Method 4: using set_axis() function. We will first create a simple dictionary of student class performance. It consists of three columns: "id", "name’" and "grade", and five rows. To convert a Python dictionary to a pandas dataframe, we will use the pandas DataFrame() function and display ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Rename column/index names of DataFrame | note.nkmk.me
August 7, 2023 - You can change all column/index names using the set_axis() method of DataFrame. pandas.DataFrame.set_axis — pandas 2.0.3 documentation
🌐
Medium
medium.com › @whyamit101 › pandas-set-column-names-a-comprehensive-guide-130c84f8761a
Pandas Set Column Names: A Comprehensive Guide | by why amit | Medium
April 12, 2025 - Yes, while pandas allows repeated column names, it’s best practice to keep them unique to avoid confusion during data manipulation and analysis. How can I check the current column names in a DataFrame? You can check the column names of a DataFrame easily using df.columns, which returns an index object containing the list of column names. Setting and changing column names is an essential skill in data manipulation with pandas.
🌐
Medium
medium.com › @heyamit10 › how-to-rename-column-names-in-pandas-c571f28b509a
How to Rename Column Names in Pandas? | by Hey Amit | Medium
April 12, 2025 - Check for Duplicates: Always ensure no duplicate column names exist; hence Pandas can become confusing. How can I rename multiple columns at once? To rename multiple columns, use the rename() function with a dictionary, or set a new list of column names.
🌐
Built In
builtin.com › data-science › rename-columns-pandas
How to Rename Columns in Pandas | Built In
Therefore, renaming columns is one of the essential steps that needs to be done at the beginning of your project. There are four common ways to rename a column in Pandas: Using dictionary with the pandas. DataFrame. rename() function.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › rename
Python Pandas DataFrame rename() - Rename Columns or Index | Vultr Docs
April 10, 2025 - In this article, you will learn how to use the rename() method to adaptively rename columns and indices in pandas DataFrames. Explore how to specify new names, use a mapping dictionary for bulk renaming, and perform in-place modifications to ...
🌐
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.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas add column names to dataframe
Pandas Add Column Names to DataFrame - Spark By {Examples}
June 27, 2025 - When using read_csv() with names, Pandas treats the first row of data as a regular row, not as headers. You can add or modify column names for an existing DataFrame by setting the df.columns attribute to a list of names.
🌐
Saturn Cloud
saturncloud.io › blog › convert-the-first-row-of-a-pandas-dataframe-to-column-names-a-comprehensive-guide
Streamlining Data Preparation: How to Set Column Names in a Pandas DataFrame from the First Row | Saturn Cloud Blog
October 20, 2023 - We then assign this row to the .columns property, which sets the column names of the DataFrame. After converting the first row to column names, the index of the DataFrame will be off by one.
🌐
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 - While directly using a list to rename columns based on a pattern might not be straightforward, you can achieve this by combining the list with other techniques like regular expressions. Can I use the set_axis() method to rename columns with ...