+4 votes
in Programming Languages by (18.8k points)
I want to check the columns present in a dataframe. What function should I use to find the column names of the dataframe?

1 Answer

0 votes
by (33.0k points)

You can use dataframe.columns to find the columns of the dataframe.

Here is an example:

>>> import pandas as pd
>>> df = pd.DataFrame({'Name':['AA','BB','CC','DD','EE','FF','GG','HH'], 'Age':[30,40,35,32,25,26,40,50], 'Salary':[1100,900,1000,4400,2550,6600,2177,1888]})
>>> df
  Name  Age  Salary
0   AA   30    1100
1   BB   40     900
2   CC   35    1000
3   DD   32    4400
4   EE   25    2550
5   FF   26    6600
6   GG   40    2177
7   HH   50    1888
>>> df.columns
Index(['Name', 'Age', 'Salary'], dtype='object')

...