Curriculum
Course: Grade XII Informatics Practices
Login
Text lesson

Ch-3 Data Handling using Pandas II

School Revise · Class 12 Information Practices · Chapter 3

Data Handling using Pandas II

Code 065, Class 12. Pandas can also summarise and tidy data. Here we find statistics, sort and group data, and handle missing values.

describe

quick statistics

groupby

summarise groups

What this chapter is about

Beyond storing data, Pandas can summarise it with statistics, sort and group it, and clean it by handling missing values.

1. Descriptive statistics

Methods like mean(), sum(), max(), min() and count() summarise a column. describe() gives several statistics at once.

import pandas as pd df = pd.DataFrame({“marks”: [80, 90, 70]}) print(df[“marks”].mean()) Output: 80.0

2. Sorting and grouping

sort_values(“col”) sorts rows by a column. groupby(“col”) groups rows so you can summarise each group, for example the average marks per class.

3. Handling missing values

Real data often has gaps. isnull() finds missing values, fillna(value) fills them, and dropna() removes rows that have them.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Find the mean of a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 90, 70]}) print(df[“marks”].mean())

OUTPUT

80.0
Problem 2. Count the values in a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 90, 70]}) print(df[“marks”].count())

OUTPUT

3
Problem 3. Find the maximum and minimum.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 95, 70]}) print(df[“marks”].max(), df[“marks”].min())

OUTPUT

95 70
Problem 4. Sort rows by a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [90, 70, 80]}) print(df.sort_values(“marks”)[“marks”].tolist())

OUTPUT

[70, 80, 90]
Problem 5. Group and average by a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“cls”: [“A”, “A”, “B”], “marks”: [80, 90, 70]}) print(df.groupby(“cls”)[“marks”].mean().tolist())

OUTPUT

[85.0, 70.0]
Problem 6. Fill a missing value.

SOLUTION

import pandas as pd import numpy as np df = pd.DataFrame({“marks”: [80, np.nan, 70]}) print(df.fillna(0)[“marks”].tolist())

OUTPUT

[80.0, 0.0, 70.0]
Problem 7. Count the missing values.

SOLUTION

import pandas as pd import numpy as np df = pd.DataFrame({“marks”: [80, np.nan, 70]}) print(df[“marks”].isnull().sum())

OUTPUT

1
Problem 8. Drop a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“a”: [1], “b”: [2]}) print(list(df.drop(“b”, axis=1).columns))

OUTPUT

[‘a’]
Problem 9. Find the total of a column.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 90, 70]}) print(df[“marks”].sum())

OUTPUT

240
Problem 10. Sort in descending order.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 95, 70]}) print(df.sort_values(“marks”, ascending=False)[“marks”].tolist())

OUTPUT

[95, 80, 70]

Practice set A, multiple choice

1. Which method gives the average of a column?

mean().

2. Which sorts a DataFrame by a column?

sort_values().

3. Which groups rows to summarise them?

groupby().

4. Which fills missing values?

fillna().

Quick summary

Pandas summarises data with mean(), sum(), max(), min(), count() and describe(). sort_values() sorts by a column and groupby() summarises each group, such as the average per class. Missing values are found with isnull(), filled with fillna() and removed with dropna().

Open the Virtual Lab

These free Class 12 Informatics Practices notes explain Pandas descriptive statistics, sorting and grouping data, groupby, and handling missing values with fillna and dropna with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Informatics Practices syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories