Get Column Names as List in Pandas DataFrame

Python Pandas, the short form from Panel Data (3D container of dataset), is a python library which contains in-built methods to manipulate, transform, visualize and analyze data. The data in the Pandas columns can contain alpha-numerical characters or logical data and can be of the similar type. The following programs illustrate to get DataFrame column headers using various methods.

The fastest and simplest way to get column header name is:


Create a Pandas DataFrame with data

Get list of column headers from a Pandas DataFrame


If you want column header names in Python Tuple :

When you use *df, please note the trailing comma.

If you want column header names in Python Set :

If you want column header names in Python List :

Pandas DataFrame follows the dict-like convention of iterating over the "keys" of the objects. So you can get column header names as:

If you want sorted column header names :

It is important to note that sorted(df) does not preserve the original order of the dataframe column header names. For that, you should use list(df) instead.
 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About