CBSE AI 417 Practical: Pandas CSV Read, Inspection & Statistics

⚡ Direct Answer & Key Takeaway

For the CBSE Class 10 AI (Code 417) 50-mark Practical, Pandas handles tabular CSV datasets using `pd.read_csv()` to load data into a two-dimensional `DataFrame`. Core workflow commands include `.head()` to preview the top five rows, `.info()` to verify column data types and non-null counts, `.describe()` for summary statistics (count, mean, std, quartiles), and `.isnull().sum()` to audit missing values before filling them with `.fillna()` or removing rows with `.dropna()`.

1. Loading CSV Files and Inspecting DataFrame Structure

Every Data Science project in CBSE AI 417 begins by importing tabular records into a Pandas `DataFrame`, which pairs labeled row indices with named columns. While school labs commonly run `pd.read_csv('students.csv')`, practical code should remain portable by passing `io.StringIO` for in-memory testing or verifying the file path in the working directory. Immediately after loading, call `df.shape` to confirm `(rows, columns)`, `df.head(3)` to view sample records, and `df.tail(2)` to catch footer artifacts. Running `df.info()` is equally vital because it reveals `Dtype` mismatches—such as numeric marks parsed as `object` strings due to stray symbols—and reports exact `Non-Null` counts per column. Catching malformed columns early prevents runtime `TypeError` failures during Part B statistical computations and model training.

  • Always inspect `df.shape` and `df.columns` immediately after `pd.read_csv()`.
  • Use `df.info()` to verify whether score columns parsed as `int64`/`float64` instead of `object`.
  • Call `df.head(n)` and `df.tail(n)` (default `n=5`) to spot header or blank-row formatting issues.

2. Computing Descriptive Statistics and Group Aggregations

Once column types are verified, Pandas summarizes distributions in a single method call. Running `df.describe()` calculates eight metrics across all numeric columns: `count`, `mean`, `std`, `min`, `25%`, `50%` (median), `75%`, and `max`. When students need a single metric for viva demonstrations, column-level methods like `df['Marks'].mean()`, `df['Marks'].median()`, and `df['Marks'].mode()[0]` isolate central tendency cleanly. Notice that `.median()` resists extreme outliers better than `.mean()`, a frequent conceptual question in Class 10 Part B and Class 12 Code 843 exams. For category-wise comparisons—such as average AI scores per section—combine `.groupby('Section')['Marks'].mean()` with `.sort_values(ascending=False)` to rank performance without writing manual loops or temporary dictionaries.

  • Extract the `50%` row from `.describe()` as the sample median of each numeric feature.
  • Access `.mode()[0]` because `.mode()` returns a `Series` to handle multimodal datasets.
  • Pair `.groupby()` with `.mean()` or `.count()` to summarize categorical cohorts cleanly.

3. Detecting and Cleaning Missing Values (NaN)

Real-world CSV datasets frequently contain blank cells that Pandas imports as `NaN` (Not a Number), which silently distort counts or break Scikit-learn estimators if left untreated. Begin every cleaning pipeline with `df.isnull().sum()` to tally missing entries per column. You then choose between two strategies based on dataset size: `df.dropna()` removes incomplete rows when data is abundant, whereas `df['Marks'].fillna(df['Marks'].mean())` preserves row count by imputing the column average. Remember that Pandas methods return a new DataFrame by default rather than mutating `df` in place; assign the result back (`df = df.fillna(...)`) so downstream filters and charts use the cleaned table. Boolean filtering like `df[df['Marks'] >= 75]` further isolates target cohorts.

  • Run `df.isnull().sum()` before and after cleaning to prove zero `NaN` values remain.
  • Assign the returned DataFrame from `.dropna()` or `.fillna()` back to `df` so edits persist.
  • Use boolean conditions (`df[df['Marks'] >= 80]`) to filter rows cleanly during practical tasks.

4. Pandas CSV Read, Missing-Value Imputation & Summary Statistics

import io
import pandas as pd

csv_data = """Student,Section,AI_Marks,Attendance
A1,A,88,92
A2,A,76,85
A3,B,,90
A4,B,94,96
A5,A,82,88"""

df = pd.read_csv(io.StringIO(csv_data))
print("Missing per column:\n", df.isnull().sum())

mean_val = df["AI_Marks"].mean()
df["AI_Marks"] = df["AI_Marks"].fillna(mean_val)

print("\nSummary Stats:\n", df[["AI_Marks", "Attendance"]].describe().round(2))
print("\nSection Averages:\n", df.groupby("Section")["AI_Marks"].mean())

Verified Console / Dry-Run Output:

Missing per column:
 Student       0
Section       0
AI_Marks      1
Attendance    0
dtype: int64

Summary Stats:
        AI_Marks  Attendance
count      5.00        5.00
mean      85.00       90.20
std        6.71        4.15
min       76.00       85.00
25%       82.00       88.00
50%       85.00       90.00
75%       88.00       92.00
max       94.00       96.00

Section Averages:
 Section
A    82.0
B    89.5
Name: AI_Marks, dtype: float64

5. Worked Pandas CSV Inspection & Cleaning Reference Table

Pandas MethodReturn Type / OutputWorked Example (`AI_Marks = [88, 76, NaN, 94, 82]`)CBSE Viva Purpose
`df.isnull().sum()``Series` of integer counts`AI_Marks: 1`, `Student: 0`Audit missing values per column
`df['AI_Marks'].mean()`Scalar `float` (skips `NaN`)`(88+76+94+82)/4 = 85.0`Compute mean for imputation
`df['AI_Marks'].median()`Scalar `float` (middle value)Sorted `[76, 82, 88, 94] -> 85.0`Robust center ignoring outliers
`df.fillna(85.0)`Cleaned `DataFrame`Replaces row `A3` `NaN` with `85.0`Preserve sample count before ML
`df[df['AI_Marks'] >= 85]`Filtered `DataFrame` subsetReturns rows `A1, A3, A4`Filter high-scoring records
🎯 1-on-1 Live Mentorship & Free Study Kit

Book a Free 1:1 CBSE AI Data Science Session with 4Achievers Junior

Master Pandas DataFrames, CSV cleaning, and data science questions for CBSE AI 417 & 843 in 1-on-1 or 1:4 Micro-Pod classes for Grades 3–12.

💬 WhatsApp Now
🔒 Instant WhatsApp notes + free 60-min 1-on-1 trial session
Confirmed! Our Senior Mentor is sending your study kit & free 1-on-1 demo link on WhatsApp now.

6. Common Mistakes & Top Scorer Tips

  • Avoid Mistake: Calling `df.fillna(0)` without reassigning `df = ...` or using `inplace=True`, leaving `NaN` values unchanged in `df`.
  • Avoid Mistake: Forgetting parentheses on methods like `df.head()` or `df.describe()`, which prints the bound method signature instead of data.
  • Avoid Mistake: Reading a CSV with Windows backslashes like `'C:\new\data.csv'` without raw strings (`r'...'`) or forward slashes, causing `FileNotFoundError`.
  • Avoid Mistake: Using `df.isnull()` alone in a print statement on large tables instead of chaining `.sum()` to get per-column missing counts.
  • Examiner / Mentor Tip: Know the exact difference between `.loc[]` (label-based inclusive slicing) and `.iloc[]` (integer-position half-open slicing).
  • Examiner / Mentor Tip: Explain why `.mean()` excludes `NaN` by default (`skipna=True`), which is why filling missing values with the mean works cleanly in one line.
  • Examiner / Mentor Tip: Keep a sample 5-row CSV memorized so you can hand-trace `.describe()` or `.groupby()` outputs in Part B board questions.

7. Interactive Concept Check Quiz

Question: Which Pandas command outputs the count, mean, standard deviation, and 50% median quartile for every numeric column in a DataFrame?

8. Frequently Asked Questions

What is the difference between a Pandas Series and a DataFrame?
A `Series` is a 1D labeled column (returned when you select `df['AI_Marks']`), whereas a `DataFrame` is a 2D labeled table made of multiple `Series` sharing a row index.
How does `df.info()` differ from `df.describe()` in CBSE practicals?
`df.info()` prints structural metadata—column names, non-null counts, and data types—while `df.describe()` computes numerical summary statistics like mean, standard deviation, min, max, and quartiles.
When should you choose `dropna()` over `fillna()`?
Use `dropna()` when missing rows are few and your dataset is large; use `fillna()` with mean, median, or mode when preserving row count is critical on small school datasets.
Why do string columns disappear in `df.describe()` output?
By default, `df.describe()` skips text (`object`) columns and summarizes only numeric columns unless you explicitly pass `include='all'`.

Explore Related Lessons & Free Interactive Tools

Free 1-on-1 Session

Book a Free Demo Class