Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🧹 Week 3 – Data Cleaning और EDA  ·  दिन 18

दिन 18: Exploratory Data Analysis (EDA)

⏱ 2.5 hours📶 Intermediate🎯 100% self-study
दिन 18 / 60

✅ आज आप सीखेंगे

  • 6-step EDA framework
  • Univariate: histograms, value counts, skew
  • IQR rule और box plots से outliers
  • Bivariate: numeric vs target, category vs target
  • Correlation heatmap और charts को insights में बदलना

🏢 असली दुनिया में

एक property start-up आपको छह शहरों की 800 house listings देकर एक सवाल पूछता है: “Price किस चीज़ से तय होता है?” किसी भी machine learning से पहले, EDA बताता है कौन से features मायने रखते हैं, कौन सी values संदिग्ध हैं और data क्या कहानी कहता है।

EDA framework

  1. 1समझें: shape, columns, types
  2. 2Quality: missing, duplicates
  3. 3Univariate: एक बार में एक column
  4. 4Outliers
  5. 5Bivariate: हर feature vs target
  6. 6Insights लिखें
हर नए dataset पर इसे अपनाएँ

Steps 1–2: समझना और quality जाँचना

Python
import pandas as pd
h = pd.read_csv("house_prices.csv")
print(h.shape)
print(h.head(3))
print("Missing:", h.isna().sum().sum(), "| duplicates:", h.duplicated().sum())
print(h.describe().round(1).T[["mean", "50%", "min", "max"]])
(800, 9) city area_sqft bedrooms bathrooms age_years metro_km furnishing parking price_lakh 0 Pune 1210 2 2 18 7.0 Furnished No 55.07 1 Bengaluru 850 2 2 15 4.6 Semi-Furnished No 48.22 2 Hyderabad 530 1 1 8 2.1 Semi-Furnished Yes 26.64 Missing: 0 | duplicates: 0 mean 50% min max area_sqft 1150.7 1090.0 400.0 3080.0 bedrooms 2.4 2.0 1.0 5.0 bathrooms 2.0 2.0 1.0 5.0 age_years 12.7 13.0 0.0 25.0 metro_km 3.4 2.3 0.2 18.0 price_lakh 56.8 54.3 10.7 200.0

Step 3: univariate analysis

Python
import pandas as pd
import matplotlib.pyplot as plt
h = pd.read_csv("house_prices.csv")
fig, ax = plt.subplots(1, 3, figsize=(12, 3.6))
ax[0].hist(h["price_lakh"], bins=30, color="#4f46e5"); ax[0].set_title("Price (₹ lakh)")
ax[1].hist(h["area_sqft"], bins=30, color="#0891b2"); ax[1].set_title("Area (sqft)")
h["city"].value_counts().plot(kind="bar", ax=ax[2], color="#f59e0b"); ax[2].set_title("Listings per city")
ax[2].tick_params(axis="x", rotation=30)
plt.tight_layout(); plt.show()
print("Skew → price:", round(h["price_lakh"].skew(), 2), "| area:", round(h["area_sqft"].skew(), 2))
Skew → price: 1.06 | area: 1.06
तीन panels: price histogram, area histogram, हर शहर की listings
Price right-skewed है: ज़्यादातर मध्यम घर और महँगे घरों की लंबी पूँछ।
📐 एक line में skewness

Skew ≈ 0: symmetric। Skew > 1: लंबी right tail (prices, incomes) – mean median से ऊपर खिंच जाता है, इसलिए median बताएँ और बाद में log transform पर विचार करें।

Step 4: IQR से outliers

Python
import pandas as pd
h = pd.read_csv("house_prices.csv")
q1, q3 = h["price_lakh"].quantile([0.25, 0.75])
iqr = q3 - q1
low, high = q1 - 1.5 * iqr, q3 + 1.5 * iqr
out = h[(h["price_lakh"] < low) | (h["price_lakh"] > high)]
print(f"Q1={q1:.1f} Q3={q3:.1f} IQR={iqr:.1f} → normal range {low:.1f} to {high:.1f} lakh")
print(len(out), "outliers")
print(out.sort_values("price_lakh", ascending=False)[["city", "area_sqft", "bedrooms", "price_lakh"]].head())
Q1=39.1 Q3=69.7 IQR=30.7 → normal range -6.9 to 115.7 lakh 19 outliers city area_sqft bedrooms price_lakh 290 Hyderabad 3080 5 199.97 217 Bengaluru 2450 5 162.50 742 Pune 2790 5 158.92 56 Bengaluru 2740 5 145.01 352 Bengaluru 2650 5 144.53
Python
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
h = pd.read_csv("house_prices.csv")
order = h.groupby("city")["price_lakh"].median().sort_values().index
plt.figure(figsize=(9, 4))
sns.boxplot(data=h, x="city", y="price_lakh", order=order, color="#a5b4fc")
plt.title("Price by city – boxes show the middle 50%, dots are outliers")
plt.ylabel("₹ lakh"); plt.show()
हर शहर की house prices का box plot
Outliers ज़्यादातर महँगे शहरों के बड़े घर हैं – असली, ग़लती नहीं। इन्हें रखें।
💡 Outlier ≠ ग़लती

असंभव values हटाएँ (negative area)। दुर्लभ पर संभव values (3,000 sqft villa) की जाँच करें। अक्सर उन्हें हटाने की जगह रखते हैं – या cap करते हैं।

Step 5: bivariate analysis

Python
import pandas as pd
import matplotlib.pyplot as plt
h = pd.read_csv("house_prices.csv")
fig, ax = plt.subplots(1, 2, figsize=(11, 4))
ax[0].scatter(h["area_sqft"], h["price_lakh"], s=10, alpha=0.5, color="#4f46e5")
ax[0].set_xlabel("Area (sqft)"); ax[0].set_ylabel("Price (₹ lakh)"); ax[0].set_title("Bigger homes cost more")
h["ppsf"] = h["price_lakh"] * 1e5 / h["area_sqft"]               # price per sqft removes the size effect
band = pd.cut(h["metro_km"], [0, 1, 2, 4, 7, 18], labels=["<1", "1-2", "2-4", "4-7", "7+"])
h.groupby(band, observed=True)["ppsf"].median().plot(kind="bar", ax=ax[1], color="#dc2626", rot=0)
ax[1].set_xlabel("Distance to metro (km)"); ax[1].set_ylabel("₹ per sqft"); ax[1].set_title("Farther from metro → cheaper per sqft")
plt.tight_layout(); plt.show()
Area vs price का scatter और metro दूरी vs price की line
Area price बढ़ाता है; metro से दूरी उसे घटाती है।
Python
import pandas as pd
h = pd.read_csv("house_prices.csv")
for col in ["furnishing", "parking", "bedrooms"]:
    print(h.groupby(col)["price_lakh"].median().round(1).to_dict())
{'Furnished': 55.8, 'Semi-Furnished': 54.1, 'Unfurnished': 52.1} {'No': 50.6, 'Yes': 56.0} {1: 35.1, 2: 47.7, 3: 62.8, 4: 80.5, 5: 102.8}
Python
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
h = pd.read_csv("house_prices.csv")
corr = h.select_dtypes("number").corr().round(2)
print(corr["price_lakh"].sort_values(ascending=False))
plt.figure(figsize=(6.5, 5))
sns.heatmap(corr, annot=True, cmap="RdBu_r", vmin=-1, vmax=1, fmt=".2f")
plt.title("Correlation matrix"); plt.show()
price_lakh 1.00 area_sqft 0.83 bedrooms 0.68 bathrooms 0.61 age_years -0.15 metro_km -0.20 Name: price_lakh, dtype: float64
House के numeric features का correlation heatmap
लाल = साथ बढ़ते हैं, नीला = उल्टे चलते हैं। Area, bedrooms और bathrooms आपस में भी correlated हैं।

Step 6: सिर्फ़ charts नहीं, insights लिखें

📏
Area सबसे ऊपरArea के साथ price लगातार बढ़ता है – सबसे मज़बूत correlation।
🚇
Metro premiumMetro के पास के घर साफ़ तौर पर महँगे।
🏙️
शहर मायने रखता हैएक ही size, Bengaluru vs Lucknow में बहुत अलग कीमत।
🏚️
पुराना = सस्तापुरानी इमारतें सस्ती; furnishing थोड़ा बढ़ाता है।
Start-up के लिए EDA summary
Python
import pandas as pd
def quick_eda(df, target):
    print("Shape:", df.shape, "| missing:", int(df.isna().sum().sum()), "| dups:", int(df.duplicated().sum()))
    num = df.select_dtypes("number").drop(columns=[target])
    print("Top numeric drivers:", num.corrwith(df[target]).abs().sort_values(ascending=False).round(2).head(3).to_dict())
    for c in df.select_dtypes("object").columns:
        g = df.groupby(c)[target].median()
        print(f"{c}: best={g.idxmax()} ({g.max():.1f}) worst={g.idxmin()} ({g.min():.1f})")
quick_eda(pd.read_csv("house_prices.csv"), "price_lakh")
Shape: (800, 9) | missing: 0 | dups: 0 Top numeric drivers: {'area_sqft': 0.83, 'bedrooms': 0.68, 'bathrooms': 0.61} city: best=Bengaluru (64.4) worst=Lucknow (36.1) furnishing: best=Furnished (55.8) worst=Unfurnished (52.1) parking: best=Yes (56.0) worst=No (50.6)

🏅 आज के Job Skills

✔ दोहराने लायक EDA checklist अपनाना✔ IQR से outliers पकड़ना✔ Features की target से तुलना✔ Charts से business insights लिखना

Practice tasks

🏋️ Practice – ख़ुद करें

Task 1: students_performance.csv पर target average के साथ quick_eda चलाएँ।
Solution देखें
Python
import pandas as pd
def quick_eda(df, target):
    num = df.select_dtypes("number").drop(columns=[target, "maths", "science", "english"])
    print(num.corrwith(df[target]).round(2).sort_values(ascending=False).to_dict())
    for c in ["gender", "school_type", "tuition", "internet", "parent_education"]:
        print(c, df.groupby(c)[target].mean().round(1).to_dict())
quick_eda(pd.read_csv("students_performance.csv"), "average")
{'study_hours': 0.79, 'attendance': 0.39} gender {'Female': 65.9, 'Male': 66.6} school_type {'Government': 66.3, 'Private': 66.3} tuition {'No': 66.3, 'Yes': 66.3} internet {'No': 63.3, 'Yes': 67.1} parent_education {'Graduate': 68.1, 'Post-Graduate': 67.0, 'School': 63.3}
Task 2: IQR rule से telecom data के monthly_charges में outliers ढूँढें।
Solution देखें
Python
import pandas as pd
t = pd.read_csv("telecom_churn.csv")
q1, q3 = t["monthly_charges"].quantile([.25, .75]); i = q3 - q1
print(((t["monthly_charges"] < q1 - 1.5 * i) | (t["monthly_charges"] > q3 + 1.5 * i)).sum(), "outliers")
0 outliers
Task 3: mall_customers.csv में spending_score से कौन सा numeric column सबसे ज़्यादा correlated है? क्या रिश्ता linear है? (Hint: scatter plot)
Solution देखें
Python
import pandas as pd
m = pd.read_csv("mall_customers.csv")
print(m.select_dtypes("number").corr()["spending_score"].round(2))
print("Age is strongly negative; income looks weak overall, yet a scatter shows clear clusters (Day 46).")
age -0.64 annual_income_lakh 0.22 spending_score 1.00 Name: spending_score, dtype: float64 Age is strongly negative; income looks weak overall, yet a scatter shows clear clusters (Day 46).

Quick quiz

🧠 Quick Quiz – ख़ुद को जाँचें

1. IQR rule किन values को flag करता है?
और Q1 − 1.5 × IQR से नीचे की।
2. Right-skewed column में…
लंबी right tail mean को ऊपर खींचती है।
3. metro_km और price का −0.6 correlation मतलब…
Negative = उल्टी दिशाएँ। Correlation, causation नहीं है।
4. शहरों में numeric distribution की तुलना का सबसे अच्छा chart?
Box plots median, फैलाव और outliers साथ-साथ दिखाते हैं।
5. असली पर दुर्लभ outlier को आमतौर पर…
असली data हटाने से असली customers छिप जाते हैं।

Interview corner

💼 Interview Corner

अपना EDA process बताइए।

Business सवाल और columns समझें; shape, types, missing values और duplicates जाँचें; हर variable देखें (histograms, value_counts); outliers पकड़ें; हर feature को target से जोड़ें (scatter, box, group medians, correlation); फिर 3–5 insights और modelling के अगले कदम लिखें।

दो features आपस में बहुत correlated हैं। क्या यह समस्या है?

Tree models से prediction में आमतौर पर नहीं। Linear models में multicollinearity होती है – अस्थिर coefficients – इसलिए एक हटाएँ, दोनों को जोड़ें या regularisation (Day 39) लें।

सारांश

  • EDA = समझना → quality → univariate → outliers → bivariate → insights।
  • Skewed data के लिए median; outliers के लिए IQR।
  • Category vs number के लिए box; number vs number के लिए scatter; correlations के लिए heatmap।
  • हमेशा लिखी हुई insights से ख़त्म करें।
➡️ आगे

Day 19: Mini project – BazaarKart की 2024 sales का पूरा EDA, management summary के साथ।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

क्या automatic EDA tools हैं?
हाँ – ydata-profiling और sweetviz HTML reports बनाते हैं। पहली नज़र के लिए अच्छे, पर सोचना और insights लिखना आपको ही है।
EDA में कितना समय लगना चाहिए?
असली projects में अक्सर 30–50% समय। यह ग़लत models रोककर बाद में कहीं ज़्यादा समय बचाता है।
← Data Science (60 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicदिन 19: Mini Project: Retail Sales EDA आपकी प्रगति: 18 / 60 (30%) · Lesson 19 / 60 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें