Class 12 CBSE - Informatics Practices Notes
Unit 1: Data Handling using Pandas - I
1. Introduction to Python Libraries
Python offers powerful libraries for data handling and visualization. The key libraries include Pandas
and Matplotlib.
a) Pandas
Pandas is an open-source library that provides data structures for efficiently storing and
manipulating structured data.
import pandas as pd
b) Matplotlib
Matplotlib is a data visualization library used to create static, interactive, and animated plots.
import matplotlib.pyplot as plt
2. Data Structures in Pandas
Pandas provides two main data structures: Series (one-dimensional) and DataFrame
(two-dimensional).
3. Series in Pandas
a) Creation of Series
Class 12 CBSE - Informatics Practices Notes
import pandas as pd
import numpy as np
# From ndarray
data = np.array([10, 20, 30, 40])
series = pd.Series(data)
# From Dictionary
data = {'a': 10, 'b': 20, 'c': 30}
series = pd.Series(data)
# From Scalar Value
series = pd.Series(5, index=['a', 'b', 'c'])
print(series)
4. DataFrame in Pandas
a) Creation of DataFrame
# From Dictionary of Series
data = {'Name': pd.Series(['Alice', 'Bob']), 'Marks': pd.Series([90, 85])}
df = pd.DataFrame(data)
# From List of Dictionaries
data = [{'Name': 'Alice', 'Marks': 90}, {'Name': 'Bob', 'Marks': 85}]
df = pd.DataFrame(data)
# From CSV
df = pd.read_csv('data.csv')
print(df)
5. Data Visualization using Matplotlib
a) Line Plot Example
Class 12 CBSE - Informatics Practices Notes
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.title("Line Plot Example")
plt.show()
6. Important Tips for Exam Preparation
- Understand the syntax and practice writing code.
- Focus on key functions like .head(), .tail(), .loc[], and .iloc[].
- Practice data visualization tasks by customizing plots with labels, legends, and titles.
- Practice both theoretical and practical questions for better understanding.