Examining the Index object
Each axis of Series and DataFrames has an Index object that labels the values. There are many different types of Index objects, but they all share the same common behavior. All Index objects, except for the special MultiIndex, are single-dimensional data structures that combine the functionality and implementation of Python sets and NumPy ndarrays.
Getting ready
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, assign for the column index to a variable, and output it:
>>> college = pd.read_csv('data/college.csv') >>> columns = college.columns >>> columns Index(['INSTNM', 'CITY', 'STABBR', 'HBCU', ...], dtype='object')
- Use the
values
attribute to access the underlying NumPy array:
>>> columns.values array(['INSTNM', 'CITY', 'STABBR', 'HBCU', ...], dtype=object)
- Select items from the index by integer location with scalars, lists, or...