KENDRIYA VIDYALAYA NO1 SAMBALPUR
CLASS – XII SUBJECT : INFORMATICS PRACTICES
CHAPTER : DATA HANDLING USING PANDAS - I
Topics to be covered : Operations on Series
Instructions to the students :
Dear students, in this topic, we are going to discuss about the operations on Series of Python
Pandas.
Read and write the following in your classwork notebook.
Operations on Series:
Python Pandas allows arithmetic operations and vector operations on Series.
Arithmetic Operations on Series:
Python Pandas allows applying arithmetic operations such as addition, subtraction,
multiplication, division, remainder etc on Series. The arithmetic operations on Series can be
performed in two ways :
(i) Using Operators : We can use the conventional arithmetic operators +, –, *, /, //, %.
For Example : Output :
0 20
1 34
dtype: int64
import pandas as pd 0 12
s1= [Link]([1, 4, 9,]) 1 16
dtype: int64
s2= [Link]([16, 25, 36]) 0 64
print(s2+s1) # Addition of s1 and s2 1 225
dtype: int64
print(s2-s1) # Subtraction of s1 from s2 0 4.000000
1 2.777778
print(s2*s1) # Multiplication of s1 and s2 dtype: float64
print(s2/s1) # Division of s2 by s1 0 4
1 2
print(s2//s1) # Integer Division of s2 by s1 dtype: int64
0 0
print(s2%s1) # Remainder of s2 by s1 1 7
dtype: int64
(ii) Using Series Functions :
Another way of performing arithmetic operations on Series is using Series Functions
add(), subtract(), multiply(), divide(), mod(). Output :
0 20
For Example : 1 34
dtype: int64
0 12
import pandas as pd 1 16
dtype: int64
s1= [Link]([4, 9]) 0 64
s2= [Link]([16, 25]) 1 225
dtype: int64
print([Link](s1)) 0 4.000000
1 2.777778
print([Link](s1)) dtype: float64
print([Link](s1)) 0 0
1 7
print([Link](s1)) dtype: int64
print([Link](s1))
Vector Operations on Series:
In vector operation, each element of the Series is applied the given operation and individual
result computed. Output :
0 6
For example : 1 8
2 11
3 14
import pandas as pd dtype: int64
s1= [Link]([3,5,8,11]) 0 12
print(s1+3) # 3 is added to each elements of s1 1 20
2 32
print(s1*4) # each elements of s1are multiplied by 4 3 44
dtype: int64
Prepared by : Sanatan Banji, PGT [Link]., KV No1 Sambalpur, Mob. No. : 9583825083