v Delete Observations With Missing Values - Machine Learning

Delete Observations With Missing Values

Preliminaries

# Load libraries
import numpy as np
import pandas as pd

Create Feature Matrix

# Create feature matrix
X = np.array([[1.1, 11.1], 
              [2.2, 22.2], 
              [3.3, 33.3], 
              [4.4, 44.4], 
              [np.nan, 55]])

Delete Observations With Missing Values

# Remove observations with missing values
X[~np.isnan(X).any(axis=1)]
array([[  1.1,  11.1],
       [  2.2,  22.2],
       [  3.3,  33.3],
       [  4.4,  44.4]])