How to delete instances with missing values in Python?

How to delete instances with missing values in Python?

This recipe helps you delete instances with missing values in Python
In [1]:
## How to delete instances with missing values in Python 
def Kickstarter_Example_29():
    print()
    print(format('How to delete instances with missing values in Python', '*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # Load libraries
    import numpy as np

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

    # Remove observations with missing values
    X = X[~np.isnan(X).any(axis=1)]
    print(); print(X)

Kickstarter_Example_29()
**************How to delete instances with missing values in Python***************

[[ 1.1 11.1]
 [ 2.2 22.2]
 [ 3.3 33.3]
 [ 4.4 44.4]]


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from HvH
1 developer from Vodafone
1 developer from Altimetrik
1 developer from KPMG
1 developer from YASH Technologies
1 developer from ANAC
1 developer from LTI
1 developer from Cognizant
1 developer from MudraCircle