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

Instruction

That's right. There is also another function that selects a specific row using indexes. In pandas, you can give each row in a DataFrame a meaningful index, other than the default sequential index. Here, we can use dataframe.set_index():

hospitals = hospitals.set_index('Phone Number')

The code above will set the Phone Number column as the index. If we now call the whole DataFrame or just the first five rows with

hospitals.head()
we will see the following:

Phone Number Hospital Name City State Hospital overall rating Full City
8643665011 Abbeville Area Medical Center Abbeville SC 4 Abbeville, SC
3378935466 Abbeville General Hospital Abbeville LA 3 Abbeville, LA
6056225000 Avera St Lukes Aberdeen SD 5 Aberdeen, SD
6056264200 Sanford Aberdeen Medical Center Aberdeen SD 4 Aberdeen, SD
3605328330 Grays Harbor Community Hospital Aberdeen WA 2 Aberdeen, WA

Instead of integers starting from 0 on the left, you can see each hospital's phone number as the index.

Exercise

Set the Country column as the index for eu_states.

Stuck? Here's a hint!

To set the index:

eu_states = eu_states.set_index('Country')