How to Rename Columns in Pandas Python?

How to Rename Columns in Pandas Python?

To rename column in pandas either use df.columns=[new columns] or you can use rename function like df.rename=(column={'old': 'new'}).

To rename columns in dataframe in Pandas python, you can either provide new columns in column property or you can use rename() function.

Consider this code –

>>> superHeroDF = pd.DataFrame({'marvel':["Ironman", "Thor"], 'dc': ["Superman", "Batman"]})
>>> superHeroDF
    marvel   dc
0   Ironman  Superman
1   Thor     Batman


In this code we have created a panda dataframe with two columns – marvel and dc. In marvel we have two superhero Ironman and Thor while in dc we have Superman and Batman. Suppose, we want to rename columns marvel and dc to avenger and justice league, then we can do it in following ways –

python python dataframe python pandas python-short

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Pandas Objects - Pandas Series and Pandas Dataframe

In this post, we will learn about pandas’ data structures/objects. Pandas provide two type of data structures:- ### Pandas Series Pandas Series is a one dimensional indexed data, which can hold datatypes like integer, string, boolean, float...

Pandas in Python

Pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.

Python Pandas Tutorial (Part 6): Add/Remove Columns From DataFrames

In this video, we will be learning how to add and remove our rows and columns. This video is sponsored by Brilliant. Go to to sign ...

Python Pandas: How To Add Rows In DataFrame

Python Pandas dataframe append() is an inbuilt function that is used to add rows in the dataframe. The loc[] and iloc[] is also way to add or modify rows.

Pandas: Python And Dataframe

Pandas is built on the NumPy package and its key data structure is called the Dataframe. There’s also another data structure supported by Pandas, called Series. We’ll be learning more about both the Series and Dataframes in this article.Pandas is mainly used for data manipulation, visualization of the data, building machine learning tools, etc. If we are using Pandas in Python, we have to be familiar with the NumPy library.