There's more...

This recipe only selects a single state. It is possible to select multiple states with both boolean and index selection. Let's select Texas (TX), California (CA), and New York (NY). With boolean selection, you can use the isin method but with indexing, just pass a list to .loc:

>>> states = ['TX', 'CA', 'NY']
>>> college[college['STABBR'].isin(states)]
>>> college2.loc[states]

There is quite a bit more to the story than what this recipe explains. Pandas implements the index differently based on whether the index is unique or sorted. See the following recipe for more details.

..................Content has been hidden....................

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