stefanuddenberg
3/8/2019 - 1:42 PM

Pandas -- Drop NA (NaN)

# Show rows with NaN
df[df.isna().any(axis=1)]

# remove NaNs
df = df.replace(
    [np.inf, -np.inf], np.nan
).dropna()


# Alternatively go by row
# Get NA subjects
na_subjects_index = df[df["Initials"].isna()].index

# Remove NA subjects
df.drop(index=na_subjects_index, axis=0, inplace=True)