CLASS NOTES
Python Programming & Data Structures
Class 12 | Informatics Practices (065) | CBSE Board
Chapter 1: Data Handling Using Pandas
Pandas is an open-source Python library used for data manipulation and analysis. It provides
two primary data structures:
• Series — a one-dimensional labeled array
• DataFrame — a two-dimensional labeled table (like a spreadsheet)
1.1 Pandas Series
A Series is like a column in a table. It holds data of a single type.
Creating a Series:
import pandas as pd
# From a list
s = [Link]([10, 20, 30, 40])
print(s)
# Output:
# 0 10
# 1 20
# 2 30
# 3 40
# dtype: int64
# From a dictionary (custom index)
marks = [Link]({'Maths': 95, 'Science': 88, 'English': 76})
print(marks['Maths']) # Output: 95
📌 The index is automatically 0, 1, 2... unless you specify custom labels.
1.2 Series Operations
You can perform arithmetic on Series — it aligns by index automatically.
a = [Link]([1, 2, 3], index=['x', 'y', 'z'])
b = [Link]([10, 20, 30], index=['x', 'y', 'z'])
print(a + b) # x=11, y=22, z=33
Useful Series attributes and methods:
Attribute/Method Description Example
[Link] Data type of elements int64, float64, object
[Link] Dimensions (rows,) (4,)
[Link] Total number of elements 4
[Link] Index labels RangeIndex(0,4)
[Link] Values as NumPy array [10 20 30 40]
[Link](n) First n elements [Link](3)
[Link](n) Last n elements [Link](2)
[Link]() Statistical summary count, mean, std...
1.3 Pandas DataFrame
A DataFrame is a 2D data structure — rows and columns, like a spreadsheet or SQL table.
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [17, 18, 17],
'Marks': [92, 78, 85]
}
df = [Link](data)
print(df)
# Output:
# Name Age Marks
# 0 Alice 17 92
# 1 Bob 18 78
# 2 Charlie 17 85
📌 CBSE Exam Tip: Know how to create a DataFrame from a dict, list of dicts, and a 2D list.
1.4 DataFrame Operations
Selecting columns:
print(df['Name']) # Single column → returns Series
print(df[['Name','Marks']]) # Multiple columns → returns DataFrame
Selecting rows using loc and iloc:
[Link][0] # Row with label 0
[Link][1] # Row at position index 1
[Link][0:2] # Rows 0 to 2 (inclusive for loc)
[Link][0:2] # Rows 0 to 1 (exclusive for iloc)
Adding and dropping columns:
df['Grade'] = ['A', 'B', 'A'] # Add column
[Link]('Grade', axis=1, inplace=True) # Drop column
Filtering rows (Boolean indexing):
high_scorers = df[df['Marks'] > 80]
print(high_scorers)
Chapter 2: Data Visualization
Python provides several libraries for plotting. The most common in CBSE IP syllabus is
Matplotlib.
import [Link] as plt
2.1 Line Plot
x = [1, 2, 3, 4, 5]
y = [10, 25, 15, 30, 20]
[Link](x, y, color='blue', marker='o', linestyle='--')
[Link]('Sales over Months')
[Link]('Month')
[Link]('Sales (in thousands)')
[Link]()
2.2 Bar Chart
subjects = ['Math', 'Science', 'English', 'IP']
scores = [90, 85, 78, 95]
[Link](subjects, scores, color='steelblue')
[Link]('Student Marks')
[Link]()
📌 Use [Link]() for a horizontal bar chart.
2.3 Histogram
data = [55, 60, 65, 70, 72, 75, 80, 85, 90, 92, 95]
[Link](data, bins=5, color='green', edgecolor='black')
[Link]('Score Distribution')
[Link]()
2.4 Scatter Plot
height = [150, 160, 170, 165, 175]
weight = [50, 60, 70, 65, 80]
[Link](height, weight, color='red', marker='^')
[Link]('Height vs Weight')
[Link]()
Chapter 3: SQL — Structured Query Language
SQL is used to manage and query relational databases. The following commands are important
for CBSE Class 12 IP.
3.1 DDL Commands (Data Definition Language)
Command Purpose Example
CREATE TABLE Creates a new table CREATE TABLE Student (RollNo
INT, Name VARCHAR(30));
ALTER TABLE Modifies table structure ALTER TABLE Student ADD Marks
INT;
DROP TABLE Deletes a table entirely DROP TABLE Student;
3.2 DML Commands (Data Manipulation Language)
-- Insert data
INSERT INTO Student VALUES (1, 'Alice', 92);
-- Select data
SELECT * FROM Student;
SELECT Name, Marks FROM Student WHERE Marks > 80;
-- Update data
UPDATE Student SET Marks = 95 WHERE RollNo = 1;
-- Delete data
DELETE FROM Student WHERE RollNo = 1;
📌 CBSE Exam Tip: WHERE filters rows. ORDER BY sorts results. GROUP BY groups rows for
aggregate functions.
3.3 Aggregate Functions
Function Description Example
COUNT() Count of rows SELECT COUNT(*) FROM Student;
SUM() Total of a column SELECT SUM(Marks) FROM Student;
AVG() Average value SELECT AVG(Marks) FROM Student;
MAX() Highest value SELECT MAX(Marks) FROM Student;
MIN() Lowest value SELECT MIN(Marks) FROM Student;
Quick Revision: Important Points
• Series is 1D; DataFrame is 2D.
• loc uses labels; iloc uses integer positions.
• Boolean indexing: df[df['col'] > value]
• [Link]() must be called to display a plot.
• DDL = CREATE, ALTER, DROP | DML = INSERT, SELECT, UPDATE, DELETE
• NULL values in SQL — use IS NULL / IS NOT NULL (not = NULL).
• Primary Key: uniquely identifies each row; cannot be NULL.
• Foreign Key: links to the Primary Key of another table.
— End of Notes — Best of luck for your Board Exams! —