# Load library
import pandas as pd

"""
Explanation: Title: Handling Outliers
Slug: handling_outliers   
Summary: How to handling outliers for machine learning in Python. 
Date: 2016-09-06 12:00
Category: Machine Learning
Tags: Preprocessing Structured Data
Authors: Chris Albon
<a alt="Handling outliers" href="https://machinelearningflashcards.com">
    <img src="handling_outliers/Outlier_print.png" class="flashcard center-block">
</a>
Preliminaries
End of explanation
"""


# Create DataFrame
houses = pd.DataFrame()
houses['Price'] = [534433, 392333, 293222, 4322032]
houses['Bathrooms'] = [2, 3.5, 2, 116]
houses['Square_Feet'] = [1500, 2500, 1500, 48000]

houses

"""
Explanation: Create Data
End of explanation
"""


# Drop observations greater than some value
houses[houses['Bathrooms'] < 20]

"""
Explanation: Option 1: Drop
End of explanation
"""


# Load library
import numpy as np

# Create feature based on boolean condition
houses['Outlier'] = np.where(houses['Bathrooms'] < 20, 0, 1)

# Show data
houses

"""
Explanation: Option 2: Mark
End of explanation
"""


# Log feature
houses['Log_Of_Square_Feet'] = [np.log(x) for x in houses['Square_Feet']]

# Show data
houses

"""
Explanation: Option 3: Rescale
End of explanation
"""


