Title: Deleting Missing Values
Slug: deleting_missing_values
Summary: How to delete missing values.
Date: 2017-09-02 12:00
Category: Machine Learning
Tags: Preprocessing Structured Data
Authors: Chris Albon
In [1]:
# Load library
import numpy as np
import pandas as pd
In [2]:
# Create feature matrix
X = np.array([[1, 2],
[6, 3],
[8, 4],
[9, 5],
[np.nan, 4]])
In [3]:
# Remove observations with missing values
X[~np.isnan(X).any(axis=1)]
Out[3]:
In [4]:
# Load data as a data frame
df = pd.DataFrame(X, columns=['feature_1', 'feature_2'])
# Remove observations with missing values
df.dropna()
Out[4]: