<filename>python/mlcookbook/handle_outliers.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)

# Load library
import numpy as np
import pandas as pd

# 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]

# Filter observations
print(houses[houses['Bathrooms'] < 20])

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

# Log feature
houses["Square_Feet_Log"] = [np.log(house) for house in houses["Square_Feet"]]

# Show data
print(houses)

<filename>python/mlcookbook/handle_outliers.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)

# Load library
import numpy as np
import pandas as pd

# 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]

# Filter observations
print(houses[houses['Bathrooms'] < 20])

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

# Log feature
houses["Square_Feet_Log"] = [np.log(house) for house in houses["Square_Feet"]]

# Show data
print(houses)

#!/usr/bin/env python # -*- coding: utf-8 -*- # Load library # Create DataFrame # Filter observations # Create feature based on boolean condition # Log feature # Show data