Thursday, October 2, 2025
HomeLanguagesPython | Pandas dataframe.keys()

Python | Pandas dataframe.keys()

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas dataframe.keys() function returns the ‘info axis’ for the pandas object. If the pandas object is series then it returns index. If the pandas object is dataframe then it returns columns. If the pandas object is panel then it returns major_axis.

Syntax: DataFrame.keys()

For link to the CSV file, click here

Example #1: Use keys() function to find the columns of a dataframe.




# importing pandas as pd
import pandas as pd
  
# Creating the dataframe 
df = pd.read_csv("nba.csv")
  
# Print the dataframe
df





# find the keys of the dataframe
df.keys()


Output :

 
Example #2: Use keys() function to find the index of the pandas series object.




# importing pandas as pd
import pandas as pd
  
# Creating the series 
sr = pd.Series([12, 5, None, 5, None, 11])
  
# Print the series
sr





# to find the index
sr.keys()


Output :

RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11927 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7079 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS