Filtering a pandas DataFrame 3


This post is the third part of filtering a pandas DataFrame. The second part is in the post called Filtering a pandas DataFrame. In this third part I look at multiple conditions.

import pandas as pd
# create a very simple DataFrame
data = {'name': ['Bob', 'Sally', 'Suzie', 'Rowan'],
       'age': [12, 14, 19, 15],
       'amount': [34.20, 65.00, 55.12, 32.09]}
df = pd.DataFrame(data)
df

Filtering a pandas DataFrame

# age > 12 and amount > 40
df[(df['age'] > 12) & (df['amount'] > 40)]

Leave a Reply