Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Series
What DataFrames are
10. Display columns names
DataFrame columns
DataFrame rows
Filtering rows and columns
Filtering data frames
Sorting rows
Summary

Instruction

Okay! When you analyze data, you often want to check the names of the columns. Each DataFrame has a field named columns that contains the names of all its columns. Take a look:

hospital.columns

This line of code returns the names of the hospital DataFrame's columns in the following format:

Index(['Hospital Name', 'City', 'State', 'Phone Number', 'Hospital overall rating'], dtype='object')

The Index object works very similarly to a Python list. You can index it or slice it in the same way as you would a Python list:

hospital.columns[3]
hospital.columns[1:5]

Exercise

Display the names of columns from the eu_states DataFrame.