While analyzing the real datasets which are often very huge in size, we might need to get the column names in order to perform some certain operations.
Let’s discuss how to get column names in Pandas dataframe.
First, let’s create a simple dataframe with
Now let’s try to get the columns name from above dataset.
Method #1: Simply iterating over columns
Method #2: Using columns with dataframe object
column.values method returs an array of index.
Method #4: Using
tolist() method with values with given the list of columns.
Method #5: Using
Sorted() method will return the list of columns sorted in alphabetical order.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to get column and row names in DataFrame?
- Python | Change column names and row indexes in Pandas DataFrame
- How to lowercase column names in Pandas dataframe
- How to Sort a Pandas DataFrame based on column names or row index?
- Add column names to dataframe in Pandas
- How to get rows/index names in Pandas dataframe
- Get column index from column name of a given Pandas DataFrame
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- Remove spaces from column names in Pandas
- Pandas - Remove special characters from column names
- Get unique values from a column in Pandas DataFrame
- Get n-smallest values from a particular column in Pandas DataFrame
- Get n-largest values from a particular column in Pandas DataFrame
- Split a column in Pandas dataframe and get part of it
- Get a list of a particular column values of a Pandas DataFrame
- Get a list of a specified column of a Pandas DataFrame
- Get list of column headers from a Pandas DataFrame
- Drop columns in DataFrame by label Names or by Index Positions
- Create a DataFrame from a Numpy array and specify the index column and column headers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.