- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Python Pandas – Display all the column names in a DataFrame
To display only the column names in a DataFrame, use dataframe.columns.
Import the required library with an alias −
import pandas as pd;
Following is the DataFrame −
dataFrame = pd.DataFrame( { "Car": ['BMW', 'Audi', 'BMW', 'Lexus', 'Tesla', 'Lexus', 'Mustang'],"Place": ['Delhi','Bangalore','Hyderabad','Chandigarh','Pune', 'Mumbai', 'Jaipur'],"Units": [100, 150, 50, 110, 90, 120, 80] } )
Example
Display the column names with dataframe.columns. Following is the complete code −
import pandas as pd; # create a DataFrame dataFrame = pd.DataFrame( { "Car": ['BMW', 'Audi', 'BMW', 'Lexus', 'Tesla', 'Lexus', 'Mustang'],"Place": ['Delhi','Bangalore','Hyderabad','Chandigarh','Pune', 'Mumbai', 'Jaipur'],"Units": [100, 150, 50, 110, 90, 120, 80] } ) print"DataFrame ...\n",dataFrame # get all the column names print"\n Display all the column names ...\n",dataFrame.columns
Output
This will produce the following output −
DataFrame ... Car Place Units 0 BMW Delhi 100 1 Audi Bangalore 150 2 BMW Hyderabad 50 3 Lexus Chandigarh 110 4 Tesla Pune 90 5 Lexus Mumbai 120 6 Mustang Jaipur 80 Display all the column names ... Index([u'Car', u'Place', u'Units'], dtype='object')
- Related Articles
- Python - Add a prefix to column names in a Pandas DataFrame
- Python - Change column names and row indexes in Pandas DataFrame
- How to rename column names in a Pandas DataFrame?
- Python - Rename column names by index in a Pandas DataFrame without using rename()
- Renaming column names – Python Pandas
- Python – Create a new column in a Pandas dataframe
- Python - Calculate the variance of a column in a Pandas DataFrame
- Python - Add a zero column to Pandas DataFrame
- Python - Display True for infinite values in a Pandas DataFrame
- Python - Summing all the rows of a Pandas Dataframe
- Python - Stacking a multi-level column in a Pandas DataFrame
- Python - Move a column to the first position in Pandas DataFrame?
- Apply uppercase to a column in Pandas dataframe in Python
- Python - Calculate the standard deviation of a column in a Pandas DataFrame
- Python Pandas - Subset DataFrame by Column Name

Advertisements