Python Practice › Pandas Programs › Program 6
Divide two Series
Write a pandas program to divide two Series.
Input
[1, 6, 9, 5], [5, 2, 4, 5]
Output
[0.2, 3.0, 2.25, 1.0]
Approach
/always gives floats.
Solution
import pandas as pda, b = pd.Series([1, 6, 9, 5]), pd.Series([5, 2, 4, 5])print((a / b).tolist())Output
[0.2, 3.0, 2.25, 1.0]
Note
9 / 4 is 2.25; the original sample showed 2.5.
Learn the concept
New to this topic? Read the lesson, then come back.