Data cleaning is the most important step in Data Science. Real-world data is messy, incomplete, and inconsistent. Clean data ensures accurate models.
df.isnull().sum()
df.fillna(df.mean()) # numeric
df.fillna("Unknown") # categorical
df.dropna()
df.drop_duplicates(inplace=True)
Using IQR method:
Q1 = df["age"].quantile(0.25)
Q3 = df["age"].quantile(0.75)
IQR = Q3 - Q1
filtered_df = df[(df["age"] >= Q1 - 1.5*IQR) & (df["age"] <= Q3 + 1.5*IQR)]
pd.get_dummies(df["gender"])
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaled = scaler.fit_transform(df)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit_transform(df)
Clean and preprocessed data leads to better accuracy and more reliable machine learning models.
Take quizzes related to this topic and see where you stand!
Start Quiz Now