- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to rename column names in a Pandas DataFrame?
To rename columns in a Pandas DataFrame, we can override df.columns with the new column names.
Steps
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame.
Override the columns with new list of column names.
Print the DataFrame again with the renamed column names.
Example
import pandas as pd df = pd.DataFrame( { "x": [5, 2, 1, 9], "y": [4, 1, 5, 10], "z": [4, 1, 5, 0] } ) print("Input DataFrame is:
", df) df.columns = ["a", "b", "c"] print("After renaming, DataFrame is:
", df)
Output
Input DataFrame is: x y z 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0 After renaming, DataFrame is: a b c 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0
- Related Articles
- Python - Rename column names by index in a Pandas DataFrame without using rename()
- How to lowercase the column names in Pandas dataframe?
- Python - How to rename multiple column headers in a Pandas DataFrame with Dictionary?
- Python - Add a prefix to column names in a Pandas DataFrame
- Python Pandas – Display all the column names in a DataFrame
- Python - Change column names and row indexes in Pandas DataFrame
- How to shift a column in a Pandas DataFrame?
- How to delete a column from Pandas DataFrame
- How to delete a column from a Pandas DataFrame?
- How to sort a column of a Pandas DataFrame?
- Apply uppercase to a column in Pandas dataframe
- Python - How to select a column from a Pandas DataFrame
- How to add column from another DataFrame in Pandas?
- Python - Add a zero column to Pandas DataFrame
- Apply uppercase to a column in Pandas dataframe in Python

Advertisements