NaN को संभालना (isnull/dropna/fillna)
NaN missing data mark करता है; आप इसे ढूंढ, remove, या fill कर सकते हैं।
In this page:
Syntax
df.isnull().sum()
df.dropna()
df.fillna(value)
NaN Handle करना (isnull/dropna/fillna)
isnull() (alias isna) वहाँ True return करता है जहाँ values missing हों, और उस पर sum() प्रति column इन्हें count करता है। dropna() missing values वाली rows या columns remove करता है, और fillna(value) इन्हें replace करता है।
आप एक constant, mean, या ffill इस्तेमाल करके previous value से भर सकते हैं।
Note:
df.isnull().sum() missing data के लिए classic पहला check है।
उदाहरण: Handling NaN (isnull/dropna/fillna)
import pandas as pd
import numpy as np
df = pd.DataFrame({"a": [1, np.nan, 3], "b": ["x", "y", None]})
print(df.isnull().sum())
print(df.dropna())
print(df.fillna({"a": df["a"].mean(), "b": "unknown"}))
# Output:
# a 1
# b 1
# dtype: int64
# a b
# 0 1.0 x
# a b
# 0 1.0 x
# 1 2.0 y
# 2 3.0 unknown
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- meaning के बारे में सोचे बिना missing values भरना
- dropna से बहुत सारी rows drop करना
- == से NaN test करना
चैप्टर सारांश
- isnull missing values ढूंढता है
- dropna इन्हें remove करता है
- fillna इन्हें replace करता है
- isnull().sum() प्रति column count करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: