How to Rename Pandas DataFrame Column in Python



Pandas is a Python library for data analysis and manipulation. Almost all operations in pandas revolve around DataFrames.

A Dataframe is is an abstract representation of a two-dimensional table which can contain all sorts of data. They also enable us give all the columns names, which is why oftentimes columns are referred to as attributes or fields when using DataFrames.

In this article we’ll see how we can rename an already existing DataFrame‘s columns.

There are two options for manipulating the column names of a DataFrame:

  1. Renaming the columns of an existing DataFrame
  2. Assigning custom column names while creating a new DataFrame

Let’s take a look at both of the methods.

Renaming Columns of an Existing Dataframe

We have a sample DataFrame below:

import pandas as pd
data = {'Name':['John', 'Doe', 'Paul'], 
        'age':[22, 31, 15]} 
df = pd.DataFrame(data)

The DataFrame



To finish reading, please visit source site