Pandas program to perform mathematical operation on two series object.

Write a program to perform mathematical operation on two Pandas series object with Practical Example

Program Logic:

  • Create two Series object using series method say s1,s2
  • Perform addition operation on two series object using arithmetic operator “+” and store result in variable ‘addition’
  • Perform subtraction operation on two series object using arithmetic operator “-” and store result in variable ‘subtraction’.
  • Perform multiplication operation on two series object using arithmetic operator “*” and store result in variable ‘multiply’
  • Perform division operation on two series object using arithmetic operator “/” and store result in variable ‘division’
  • Perform modulus operation on two series object using arithmetic operator “%” and store result in variable ‘modulus’
  • Print all the variable on output screen using print function for each variable.

Below is implementation code/Source code

Here is program for performing arithmetic operation on two series object. The output is also shown below

import pandas as pd
s1 = pd.Series([22,44,66,88,100])
s2 = pd.Series([11,22,33,44,55])
addition = s1+s2
print("Addition of two Series object:")
print(addition)
substraction = s1-s2
print("Subtraction of two Series object:")
print(substraction)
multiply = s1*s2
print("Product of two Series object:")
print(multiply)
division = s1/s2
print("Division of two Series object:")
print(division)
modulus = s1%s2
print("Modulus of two Series object:")
print(modulus)

Below is Output:

Addition of two Series object:
0     33
1     66
2     99
3    132
4    155
dtype: int64
Subtraction of two Series object:
0    11
1    22
2    33
3    44
4    45
dtype: int64
Product of two Series object:
0     242
1     968
2    2178
3    3872
4    5500
dtype: int64
Division of two Series object:
0    2.000000
1    2.000000
2    2.000000
3    2.000000
4    1.818182
dtype: float64
Modulus of two Series object:
0     0
1     0
2     0
3     0
4    45
dtype: int64

Below is snapshot of executable code

Below is snapshot of Output

You can check this too:

<