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.