How to do it...

  1. Read in the college dataset, and set the institution name as the index:
>>> college = pd.read_csv('data/college.csv', index_col='INSTNM')
  1. Attempt to select all colleges with names lexicographically between 'Sp' and 'Su':
>>> college.loc['Sp':'Su']KeyError: 'Sp'
  1. As the index is not sorted, the preceding command fails. Let's go ahead and sort the index:
>>> college = college.sort_index()
  1. Now, let's rerun the same command from step 2:
>>> college.loc['Sp':'Su']

Get Numerical Computing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.