Title: Select Rows With Multiple Filters
Slug: pandas_select_rows_multiple_filters
Summary: Select Rows With Multiple Filters
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon


In [1]:
# import pandas as pd
import pandas as pd

In [2]:
# Create an example dataframe
data = {'name': ['A', 'B', 'C', 'D', 'E'], 
        'score': [1,2,3,4,5]}
df = pd.DataFrame(data)
df


Out[2]:
name score
0 A 1
1 B 2
2 C 3
3 D 4
4 E 5

In [3]:
# Select rows of the dataframe where df.score is greater than 1 and less and 5
df[(df['score'] > 1) & (df['score'] < 5)]


Out[3]:
name score
1 B 2
2 C 3
3 D 4