Ravindra BagaleCourses & study guides Track your progress

Guides

pandas में missing values कैसे handle करें

Read this guide in: English · मराठी · हिंदी

Missing values NaN दिखते हैं। पहले detect करो, फिर dropna या fillna चुनो, फिर totals फिर से check। Netflix-style: watches 100, NaN, 90 → fillna(0) के बाद sum 190.

दोस्तों! खाली cells naive sums तोड़ती हैं और charts उलझाती हैं। आज missing watches ईमानदार rules से clean करते हैं — जादू नहीं। समझा? आख़िर में फिर check।

संक्षिप्त उत्तर

खड़ा cleaning path:

  1. df.isna().sum() — हर column कितने missing।
  2. Rows देखो: df[df["watches"].isna()]
  3. Decide: row drop, या 0 / median / labels से fill।
  4. dropna या fillna लगाओ।
  5. info() और known sum फिर चलाओ।
  6. Notebook में choice एक वाक्य में लिखो।
detect → decide → dropna/fillna → verify → document

Language: English · मराठी · हिंदी

इस guide से पहले क्या चाहिए?

Before और after

Before fillna One missing watch count.

Before — Netflix-style watches with a NaN.

After fillna NaN filled with 0; total 190.

After — fillna(0); watches total 190.

Before: Show B = NaN। After: 0 fill; total 190.

Missing क्यों?

Export blank, API skip, spaces, join gaps। Chart NaNs को चुपचाप गिरा सकता है।

Netflix-style sample

import pandas as pd
import numpy as np

df = pd.DataFrame({
    "title": ["Show A", "Show B", "Show C"],
    "watches": [100, np.nan, 90],
})
df.isna().sum()

watches missing 1.

Detect → decide → apply

clean = df.dropna(subset=["watches"])
df["watches"] = df["watches"].fillna(0)
print(df["watches"].sum())  # 190

Counts के लिए 0 अक्सर ईमानदार। Categories के लिए "unknown". Mean fill autopilot पर मत।

Shop blank sales

असली sale पर बिना business पूछे 0 मत भरें। Blank = “कोई sale line नहीं” हो तो drop सोचो।

Strip / coerce पहले

df["watches"] = pd.to_numeric(df["watches"], errors="coerce")

Duplicates ≠ missing; outliers ≠ NaN

अलग बीमारियाँ — अलग फैसले।

Ravindra Bagale's Tip

“सब mean से fill” autopilot मत चलाओ। Watch counts पर zero ठीक हो सकता है; salary पर mean झूठ बोल सकता है। Rule code के पास लिखो। समझा?

Practice task

  1. तीन-row watches + एक NaN।
  2. isna().sum().
  3. fillna(0) → 190.
  4. dropna copy; दोनों totals यहाँ क्यों 190 — Show B=50 पर क्यों नहीं — लिखो।

Samajla ka? NaN detect, drop या fill, total verify, rule लिखो। फिर EDA। अब आगे चलें।

Frequently asked questions

What is NaN?

Not a Number — pandas marker for missing numeric/object values in many cases.

Is empty string the same as NaN?

Not always. Strip and replace "" with pd.NA / np.nan during cleaning when needed.

When is dropna wrong?

If most rows miss one optional column, dropping can delete good data — fill or keep and filter later.

fillna mean?

Possible for some numeric EDA; for counts, 0 or “unknown” may be clearer. Be honest in the write-up.

Duplicates too?

Same cleaning chapter covers duplicates — handle missing and dupes as separate decisions.

Course links?

Data cleaning chapter: types, missing, duplicates.