# Import modules
import pandas as pd
import numpy as np

# Create a dataframe
raw_data = {'first_name': ['Jason', 'Molly', np.nan, np.nan, np.nan], 
        'nationality': ['USA', 'USA', 'France', 'UK', 'UK'], 
        'age': [42, 52, 36, 24, 70]}
df = pd.DataFrame(raw_data, columns = ['first_name', 'nationality', 'age'])
df

"""
Explanation: Title: Selecting Pandas DataFrame Rows Based On Conditions
Slug: pandas_selecting_rows_on_conditions
Summary: Selecting Pandas DataFrame Rows Based On Conditions
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon  
Preliminaries
End of explanation
"""


# Create variable with TRUE if nationality is USA
american = df['nationality'] == "USA"

# Create variable with TRUE if age is greater than 50
elderly = df['age'] > 50

# Select all casess where nationality is USA and age is greater than 50
df[american & elderly]

"""
Explanation: Method 1: Using Boolean Variables
End of explanation
"""


# Select all cases where the first name is not missing and nationality is USA 
df[df['first_name'].notnull() & (df['nationality'] == "USA")]

"""
Explanation: Method 2: Using variable attributes
End of explanation
"""


