Pandas & EDA
DataFrames, CSV loading, groupby — understand your data before you build any model.
A Swiggy data scientist built a delivery-time model that predicted negative times. The bug? One city's distances were stored in miles, all others in km. The model learned nonsense.
Exploratory Data Analysis (EDA) — looking at your data before modelling — would have caught it in 2 minutes. Bad data beats good models every time.
📈 Core Concepts (5–25 min)
load — pd.read_csv() turns a file into a DataFrame.
explore — df.describe(), df.info(), df.isnull().sum().
filter & select — df[df["score"] > 80], df[["name","score"]].
aggregate — df.groupby("city")["sales"].mean().
💻 Live Demo — Student Grade EDA (25–45 min)
>import pandas as pd import numpy as np # Create a sample dataset (in real life: pd.read_csv("grades.csv")) df = pd.DataFrame({ "name": ["Priya", "Ravi", "Ananya", "Kiran", "Divya"], "city": ["Chennai", "Mumbai", "Chennai", "Mumbai", "Bengaluru"], "math": [88, 72, 95, 60, 85], "science": [76, 85, 90, 55, 92], "grade": ["B", "B", "A", "C", "A"] }) # 1. Quick overview print(df.describe()) # mean, std, min, max per column print(df.isnull().sum()) # missing values per column # 2. Filter: students who passed both subjects passed = df[(df["math"] >= 60) & (df["science"] >= 60)] print(passed[["name", "grade"]]) # 3. Groupby: average score by city city_avg = df.groupby("city")[["math", "science"]].mean().round(1) print(city_avg) # 4. Add derived column df["avg"] = (df["math"] + df["science"]) / 2 df["result"] = df["avg"].apply(lambda x: "Pass" if x >= 60 else "Fail") print(df[["name", "avg", "result"]])
📋 You Code It (45–55 min)
Add a 6th student with a missing math score (use None). Find how many nulls exist. Fill the null with the column mean. Then filter students with avg >= 75 and print their names.
⚡ Day 3 Cheat Sheet
pd.read_csv("file.csv")df.describe()df.isnull().sum()df.fillna(df.mean())df[df["col"] > 60]df.groupby("col").mean()df["new"] = df["a"] + df["b"]df.sort_values("col")