chevron_left
Iterators
0
0
0
new
Pandas DataFrame | keys method
Programming
chevron_rightPython
chevron_rightPandas
chevron_rightDocumentation
chevron_rightDataFrame
chevron_rightIterators
schedule Mar 10, 2022
Last updated Python●Pandas
Tags tocTable of Contents
expand_more Pandas DataFrame.keys()
method returns the columns of the DataFrame as an Index
object.
Examples
Consider the following DataFrame:
df
A B0 3 51 4 6
To get the columns of df
:
df.keys()
Index(['A', 'B'], dtype='object')
The returned value is of type Index
, and so you can access the actual column labels using []
syntax like so:
df.keys()[0]
'A'
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
Official Pandas Documentation
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.keys.html