- Read in the college dataset and use boolean indexing to select all institutions from the state of Texas (TX):
>>> college = pd.read_csv('data/college.csv')>>> college[college['STABBR'] == 'TX'].head()
Pandas official documentation on
- To replicate this using index selection, we need to move the STABBR column into the index. We can then use label-based selection with the .loc indexer:
>>> college2 = college.set_index('STABBR')>>> college2.loc['TX'].head()
- Let's compare the speed of both methods:
>>> %timeit college[college['STABBR'] ...