There's more...

It is important to be aware that this lazy slicing does not work for columns, just for DataFrame rows and Series. It also cannot be used to select both rows and columns simultaneously. Take, for instance, the following code, which attempts to select the first ten rows and two columns:

>>> college[:10, ['CITY', 'STABBR']]
TypeError: unhashable type: 'slice'

To make a selection in this manner, you need to use .loc or .iloc. Here is one possible way that selects all the institution labels first and then uses the label-based indexer .loc:

>>> first_ten_instnm = college.index[:10]
>>> college.loc[first_ten_instnm, ['CITY', 'STABBR']]
..................Content has been hidden....................

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