3. Write a Python Pandas program first to carry out the mathematics operations for the following two series a1 and a2. The mathematics operations are addition, subtraction, multiplication and division.
The output is:
a1 = [6, 6, 6, 6, 6]
a2 = [1, 2, 5, 7, 9]
Expected Answer:
Addition of two Series:
0 7
1 8
2 11
3 13
4 15
dtype: int64
Subtraction of two Series:
0 5
1 4
2 1
3 -1
4 -3
dtype: int64
Multiplication of two Series:
0 6
1 12
2 30
3 42
4 54
dtype: int64
Division of Series1 by Series2:
0 6.000000
1 3.000000
2 1.200000
3 0.857143
4 0.666667
dtype: float64
Sample Answer:
import pandas as pd a1 = pd.Series([6, 6, 6, 6, 6]) a2 = pd.Series([1, 2, 5, 7, 9]) addition = a1 + a2 print("Addition of two Series:") print(addition) subtraction = a1 - a2 print("\nSubtraction of two Series:") print(subtraction) multiplication = a1 * a2 print("\nMultiplication of two Series:") print(multiplication) Division = a1 / a2 print("\nDivision of Series1 by Series2:") print(Division)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)