Skip to main content
TopMiniSite

Back to all posts

How to Rename Pandas Dataframe Column?

Published on
4 min read
How to Rename Pandas Dataframe Column? image

Best Python Programming Guides to Buy in October 2025

1 Python Crash Course, 3rd Edition: A Hands-On, Project-Based Introduction to Programming

Python Crash Course, 3rd Edition: A Hands-On, Project-Based Introduction to Programming

BUY & SAVE
$27.53 $49.99
Save 45%
Python Crash Course, 3rd Edition: A Hands-On, Project-Based Introduction to Programming
2 Python Programming for Beginners: The Complete Python Coding Crash Course - Boost Your Growth with an Innovative Ultra-Fast Learning Framework and Exclusive Hands-On Interactive Exercises & Projects

Python Programming for Beginners: The Complete Python Coding Crash Course - Boost Your Growth with an Innovative Ultra-Fast Learning Framework and Exclusive Hands-On Interactive Exercises & Projects

BUY & SAVE
$19.95
Python Programming for Beginners: The Complete Python Coding Crash Course - Boost Your Growth with an Innovative Ultra-Fast Learning Framework and Exclusive Hands-On Interactive Exercises & Projects
3 Learning Python: Powerful Object-Oriented Programming

Learning Python: Powerful Object-Oriented Programming

BUY & SAVE
$64.27 $79.99
Save 20%
Learning Python: Powerful Object-Oriented Programming
4 Python Programming for Beginners: The Complete Guide to Mastering Python in 7 Days with Hands-On Exercises – Top Secret Coding Tips to Get an Unfair Advantage and Land Your Dream Job!

Python Programming for Beginners: The Complete Guide to Mastering Python in 7 Days with Hands-On Exercises – Top Secret Coding Tips to Get an Unfair Advantage and Land Your Dream Job!

BUY & SAVE
$24.99
Python Programming for Beginners: The Complete Guide to Mastering Python in 7 Days with Hands-On Exercises – Top Secret Coding Tips to Get an Unfair Advantage and Land Your Dream Job!
5 Python Programming Language: a QuickStudy Laminated Reference Guide

Python Programming Language: a QuickStudy Laminated Reference Guide

BUY & SAVE
$8.95
Python Programming Language: a QuickStudy Laminated Reference Guide
6 Python 3: The Comprehensive Guide to Hands-On Python Programming (Rheinwerk Computing)

Python 3: The Comprehensive Guide to Hands-On Python Programming (Rheinwerk Computing)

BUY & SAVE
$41.31 $59.95
Save 31%
Python 3: The Comprehensive Guide to Hands-On Python Programming (Rheinwerk Computing)
7 Fluent Python: Clear, Concise, and Effective Programming

Fluent Python: Clear, Concise, and Effective Programming

BUY & SAVE
$43.99 $79.99
Save 45%
Fluent Python: Clear, Concise, and Effective Programming
8 Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners

Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners

  • LEARN PYTHON EFFORTLESSLY WITH A BEGINNER-FRIENDLY APPROACH!
  • PREMIUM QUALITY BOOK DESIGNED FOR PRACTICAL PROGRAMMING SKILLS.
  • AUTOMATE TASKS AND BOOST PRODUCTIVITY WITH REAL-WORLD EXAMPLES!
BUY & SAVE
$38.00 $49.99
Save 24%
Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners
9 Python Programming: An Introduction to Computer Science, Fourth Edition

Python Programming: An Introduction to Computer Science, Fourth Edition

BUY & SAVE
$65.00
Python Programming: An Introduction to Computer Science, Fourth Edition
+
ONE MORE?

To rename a column in a pandas DataFrame, you can use the [rename()](https://devhubby.com/thread/how-to-change-the-name-of-a-value-in-r) method and specify the old column name as the key and the new column name as the value in a dictionary. For example, if you have a DataFrame called df and you want to rename the column "old_name" to "new_name", you can use the following code:

df.rename(columns={"old_name": "new_name"}, inplace=True)

Make sure to set inplace=True so that the changes are applied to the original DataFrame. Alternatively, you can assign the result to a new DataFrame if you want to keep the original unchanged:

new_df = df.rename(columns={"old_name": "new_name"})

This will create a new DataFrame called new_df with the updated column name.

How to rename a pandas DataFrame column?

To rename a column in a Pandas DataFrame, you can use the rename() method.

Here's an example:

import pandas as pd

Create a DataFrame

data = {'A': [1, 2, 3], 'B': [4, 5, 6]} df = pd.DataFrame(data)

Rename column 'A' to 'New_Column'

df = df.rename(columns={'A': 'New_Column'})

print(df)

This will rename the column 'A' to 'New_Column' in the DataFrame.

What is the most efficient way to rename columns in pandas DataFrame?

The most efficient way to rename columns in a pandas DataFrame is to use the rename method. You can specify new column names using a dictionary where the keys are the current column names and the values are the new column names.

For example, if you have a DataFrame df with columns "A" and "B" and you want to rename them to "Column1" and "Column2" respectively, you can use the following code:

df.rename(columns={'A': 'Column1', 'B': 'Column2'}, inplace=True)

Setting inplace=True will modify the original DataFrame instead of creating a new one. This method is efficient because it does not require iterating over each row or column individually.

How to assign new names to columns in pandas DataFrame?

You can assign new names to columns in a pandas DataFrame by accessing the columns attribute of the DataFrame and assigning a list of new column names to it. Here's an example:

import pandas as pd

Create a DataFrame

data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]} df = pd.DataFrame(data)

Display the original column names

print("Original column names:") print(df.columns)

Assign new column names

new_columns = ['X', 'Y', 'Z'] df.columns = new_columns

Display the DataFrame with the new column names

print("\nDataFrame with new column names:") print(df)

Output:

Original column names: Index(['A', 'B', 'C'], dtype='object')

DataFrame with new column names: X Y Z 0 1 4 7 1 2 5 8 2 3 6 9

How to change the name of a column in pandas DataFrame?

You can change the name of a column in a pandas DataFrame by using the rename() method. Here is an example:

import pandas as pd

Create a sample DataFrame

data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}

df = pd.DataFrame(data)

Display the original DataFrame

print("Original DataFrame:") print(df)

Rename the column 'A' to 'Column1'

df = df.rename(columns={'A': 'Column1'})

Display the DataFrame with the renamed column

print("\nDataFrame with renamed column:") print(df)

Output:

Original DataFrame: A B C 0 1 4 7 1 2 5 8 2 3 6 9

DataFrame with renamed column: Column1 B C 0 1 4 7 1 2 5 8 2 3 6 9

In this example, we renamed the column 'A' to 'Column1' using the rename() method. You can specify the new name of the column inside the columns parameter as a dictionary where the key is the old column name and the value is the new column name.