Operations on Pandas Series | Head(), Tail(), Indexing & Slicing | CBSE Class 12 Informatics Practices (2026–27)
Class 12 · Informatics Practices
Operations on Pandas Series
After creating a Series, we can perform various operations such as mathematical calculations, selecting data, indexing, slicing, and viewing records. These operations help analyze and manipulate data efficiently.
Mathematical Operations on Series
Pandas allows arithmetic operations to be performed directly on all elements of a Series.
Addition
import pandas as pd marks = pd.Series([60, 70, 80, 90]) print(marks + 5)Output
0 65 1 75 2 85 3 95 dtype: int64
Subtraction
import pandas as pd marks = pd.Series([60,70,80,90]) print(marks - 10)Output
0 50 1 60 2 70 3 80 dtype: int64
Multiplication
import pandas as pd marks = pd.Series([10,20,30]) print(marks * 2)Output
0 20 1 40 2 60 dtype:int64
Division
import pandas as pd marks = pd.Series([20,40,60]) print(marks / 2)Output
0 10.0 1 20.0 2 30.0 dtype: float64
Mathematical Operators Supported
| Operator | Operation |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| // | Floor Division |
| % | Modulus |
| ** | Power |
head() Function
The head() function displays the first five records of a Series by default.
Syntax
Series.head(n)
- If n is omitted, the first 5 records are displayed.
- If n is specified, the first n records are displayed.
Example
import pandas as pd s = pd.Series([10,20,30,40,50,60,70]) print(s.head())Output
0 10 1 20 2 30 3 40 4 50 dtype:int64
head(3)
print(s.head(3))Output
0 10 1 20 2 30 dtype:int64
tail() Function
The tail() function displays the last five records by default.
Syntax
Series.tail(n)
Example
print(s.tail())Output
2 30 3 40 4 50 5 60 6 70 dtype:int64
tail(2)
print(s.tail(2))Output
5 60 6 70 dtype:int64
Selecting Elements from Series
Elements can be selected using their index values.
Syntax
Series[index]
Example
import pandas as pd marks = pd.Series([85,90,78,95]) print(marks[2])Output
78
Accessing Multiple Elements
print(marks[[0,2]])Output
0 85 2 78 dtype:int64
Indexing
Every value in a Series has an associated index.
Default Index
0 1 2 3
Custom Index
A B C D
Example of Custom Index
import pandas as pd marks = pd.Series([85,90,95],index=["A","B","C"]) print(marks["B"])Output
90
Slicing
Slicing extracts a range of values from a Series.
Syntax
Series[start:stop]
Example
import pandas as pd marks = pd.Series([60,70,80,90,95]) print(marks[1:4])Output
1 70 2 80 3 90 dtype:int64
Slicing with Custom Index
import pandas as pd marks = pd.Series( [60,70,80,90], index=["A","B","C","D"] ) print(marks["B":"D"])Output
B 70 C 80 D 90 dtype:int64
Difference Between Indexing and Slicing
| Indexing | Slicing |
|---|---|
| Returns one element. | Returns multiple elements. |
| Uses a single index. | Uses a range of indexes. |
| Example: s[2] | Example: s[1:4] |
Common Errors
| Error | Reason |
|---|---|
| KeyError | Index label does not exist. |
| IndexError | Index is outside the Series range. |
| TypeError | Invalid index type used. |
Quick Revision
| Function | Purpose |
|---|---|
| head() | Shows first 5 records. |
| tail() | Shows last 5 records. |
| s[2] | Select one element. |
| s[1:4] | Select multiple elements. |
| + | Addition |
| * | Multiplication |
CBSE Exam Tips
- Remember that
head()andtail()display 5 records by default. - Understand the difference between indexing and slicing.
- Practice predicting the output of Series programs.
- Know that arithmetic operations are applied to every element.
- Be comfortable using both default and custom indexes.
Summary
Pandas Series supports powerful operations such as arithmetic calculations, indexing, slicing, and viewing data with head() and tail(). These features make data analysis simple and efficient and form the foundation for working with DataFrames in Pandas.