← Back to Pandas Course | Chapter 5: Data Cleaning | Lesson 1 of 7

NaN को संभालना (isnull/dropna/fillna)

NaN missing data mark करता है; आप इसे ढूंढ, remove, या fill कर सकते हैं।
Syntax
python
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)

python
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. #}
आम गलतियां
  1. meaning के बारे में सोचे बिना missing values भरना
  2. dropna से बहुत सारी rows drop करना
  3. == से 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.