Curriculum
Course: Grade XII Informatics Practices
Login
Text lesson

Ch-2 Data Handling using Pandas I

School Revise · Class 12 Information Practices · Chapter 2

Data Handling using Pandas I

Code 065, Class 12. Pandas is a Python library for working with data. Here we meet its two main structures, the Series and the DataFrame.

Series

a labelled column

DataFrame

a table

What this chapter is about

Pandas handles data in Python. A Series is a single labelled column of values. A DataFrame is a table with rows and columns.

1. Series

A Series holds values with an index (labels). We create it from a list, and read a value by its label or position.

import pandas as pd s = pd.Series([10, 20, 30]) print(s[1]) Output: 20

2. DataFrame

A DataFrame is a table. We often make one from a dictionary, where each key is a column. We read a column with df[“column”].

3. Import and export

Pandas can read and write data files. read_csv() loads a CSV file into a DataFrame, and to_csv() saves a DataFrame to a CSV file.

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. Create a Series from a list.

SOLUTION

import pandas as pd s = pd.Series([10, 20, 30]) print(s.tolist())

OUTPUT

[10, 20, 30]
Problem 2. Read a Series value by its index.

SOLUTION

import pandas as pd s = pd.Series([1, 2, 3], index=[“a”, “b”, “c”]) print(s[“b”])

OUTPUT

2
Problem 3. Create a DataFrame from a dictionary.

SOLUTION

import pandas as pd df = pd.DataFrame({“name”: [“A”, “B”], “marks”: [80, 90]}) print(df.shape)

OUTPUT

(2, 2)
Problem 4. Read one column of a DataFrame.

SOLUTION

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

OUTPUT

[80, 90]
Problem 5. Show the first two rows with head.

SOLUTION

import pandas as pd df = pd.DataFrame({“n”: [1, 2, 3, 4]}) print(df.head(2)[“n”].tolist())

OUTPUT

[1, 2]
Problem 6. Add a new column.

SOLUTION

import pandas as pd df = pd.DataFrame({“marks”: [80, 20]}) df[“pass”] = df[“marks”] >= 33 print(df[“pass”].tolist())

OUTPUT

[True, False]
Problem 7. Find the number of rows and columns.

SOLUTION

import pandas as pd df = pd.DataFrame({“a”: [1, 2, 3], “b”: [4, 5, 6]}) print(df.shape)

OUTPUT

(3, 2)
Problem 8. Find the sum of a column.

SOLUTION

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

OUTPUT

240
Problem 9. List the column names.

SOLUTION

import pandas as pd df = pd.DataFrame({“name”: [1], “marks”: [2]}) print(list(df.columns))

OUTPUT

[‘name’, ‘marks’]
Problem 10. Find the maximum in a column.

SOLUTION

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

OUTPUT

95

Practice set A, multiple choice

1. What is a Series in Pandas?

A single labelled column of values.

2. What is a DataFrame?

A table with rows and columns.

3. Which method reads a CSV file?

read_csv().

4. df.shape gives the …

number of rows and columns.

Quick summary

Pandas handles data in Python. A Series is one labelled column, read by label or position. A DataFrame is a table, often made from a dictionary of columns and read with df[“column”]. read_csv() loads a CSV into a DataFrame and to_csv() saves it. df.shape gives the number of rows and columns.

Open the Virtual Lab

These free Class 12 Informatics Practices notes explain the Pandas library, Series and DataFrame, creating and reading them, and importing and exporting CSV data 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