Kickstart 2020 with new opportunities! - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Series
What DataFrames are
DataFrame columns
DataFrame rows
Filtering rows and columns
Filtering data frames
25. Filtering rows with conditions
Sorting rows
Summary

## Instruction

You can filter your DataFrame by providing conditions. Suppose we would like to get a list of hospitals that have rating greater than 3:

hospitals[hospitals['Hospital overall rating'] > 3]

The condition hospitals['Hospital overall rating'] > 3 returns a Series of Boolean (True or False) values:

 0 True 1 False 2 True ... ...

The bracket syntax returns rows for which the corresponding value in the Series is True (in our case, hospitals with a rating greater than 3):

Hospital Name ... Hospital overall rating
0 Abbeville Area Medical Center ... 4
2 Avera St Lukes ... 5
... ... ... ...

It's a good idea to assign the conditional Series to a separate variable, to make the code more readable.

south_carolina = hospitals['State'] == "SC"
hospitals[south_carolina]


Note that here we're comparing each value in the State column to a string.

## Exercise

Show the countries where the GDP is greater than 25000.