drop missing values in a column pandas
df = df[pd.notnull(df['RespondentID'])]
# Drop the missing value present in the "RespondentID" column
drop missing values in a column pandas
df = df[pd.notnull(df['RespondentID'])]
# Drop the missing value present in the "RespondentID" column
replace missing values, encoded as np.nan, using the mean value of the columns
# Univariate feature imputation
import numpy as np
from sklearn.impute import SimpleImputer
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
imp.fit([[1, 2], [np.nan, 3], [7, 6]])
# SimpleImputer()
X = [[np.nan, 2], [6, np.nan], [7, 6]]
print(imp.transform(X))
# [[4. 2. ]
# [6. 3.666...]
# [7. 6. ]]
# SimpleImputer class also supports categorical data
import pandas as pd
df = pd.DataFrame([["a", "x"],
[np.nan, "y"],
["a", np.nan],
["b", "y"]], dtype="category")
imp = SimpleImputer(strategy="most_frequent")
print(imp.fit_transform(df))
# [['a' 'x']
# ['a' 'y']
# ['a' 'y']
# ['b' 'y']]
handling missing dvalues denoted by a '?' in pandas
# Making a list of missing value typesmissing_values = ["n/a", "na", "--"]df = pd.read_csv("property data.csv", na_values = missing_values)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us