How to do it...

  1. Read in the college dataset with the institution name as the index and then select every other row from index 10 to 20:
>>> college = pd.read_csv('data/college.csv', index_col='INSTNM')
>>> college[10:20:2]
  1. This same slicing exists with Series:
>>> city = college['CITY']
>>> city[10:20:2]
INSTNM Birmingham Southern College Birmingham Concordia College Alabama Selma Enterprise State Community College Enterprise Faulkner University Montgomery New Beginning College of Cosmetology Albertville Name: CITY, dtype: object

  1. Both Series and DataFrames can slice by label as well with just the indexing operator:
>>> start = 'Mesa Community College'
>>> stop = 'Spokane Community College'
>>> college[start:stop:1500]
  1. Here is the same slice by label with a Series:
>>> city[start:stop:1500]
INSTNM Mesa Community College Mesa Hair Academy Inc-New Carrollton New Carrollton National College of Natural Medicine Portland Name: CITY, dtype: object
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset