Introduction
Series
What DataFrames are
DataFrame columns
DataFrame rows
Filtering rows and columns
Filtering data frames
27. Combining loc and filtering
Sorting rows
Summary

Instruction

Great! Why don't we combine everything we've learned? It is pretty useful to combine the loc function and filtering to get only a few columns from the rows that meet certain conditions. For example, we would like to see only the names of the hospitals that are located in Aberdeen and have overall rating greater than 4.

aberdeen_hospitals = hospitals['City'] == 'Aberdeen'
hospital_rating = hospitals['Hospital overall rating'] > 4

hospitals.loc[ aberdeen_hospitals & hospital_rating, 'Hospital Name']

Note that we used the loc function and then provided our conditions in the same way as before. The only difference is that we also provided the name of the column we want to see after a comma.

Exercise

Select only the Country and GDP columns for countries that joined the European Union after the year 2000, and use the Euro as their currency.

The information about join date is in the Accession Year column.

Stuck? Here's a hint!

In order to provide a few column names, you have to wrap them in parentheses:

eu_states.loc[... , ('Country', 'GDP')]