Examining the Index object
As was discussed previously, each axis of a Series and a DataFrame has an Index object that labels the values. There are many different types of Index objects, but they all share common behavior. All Index objects, except for the MultiIndex, are single-dimensional data structures that combine the functionality of Python sets and NumPy ndarrays.
In this recipe, we will examine the column index of the college dataset and explore much of its functionality.
How to do it…
- Read in the college dataset, and create a variable
columns
that holds the column index:>>> import pandas as pd >>> import numpy as np >>> college = pd.read_csv("data/college.csv") >>> columns = college.columns >>> columns Index(['INSTNM', 'CITY', 'STABBR', 'HBCU', 'MENONLY', 'WOMENONLY', 'RELAFFIL', 'SATVRMID&apos...