Write a Pandas program to add, subtract, multiple and divide two Pandas Series.Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
import pandas as pd ds1 = pd.Series([2, 4, 6, 8, 10]) ds2 = pd.Series([1, 3, 5, 7, 9]) ds = ds1 + ds2 print("Add two Series:") print(ds) print("Subtract two Series:") ds = ds1 - ds2 print(ds) print("Multiply two Series:") ds = ds1 * ds2 print(ds) print("Divide Series1 by Series2:") ds = ds1 / ds2 print(ds)
Sample Output:
Add two Series: 0 3 1 7 2 11 3 15 4 19 dtype: int64 Subtract two Series: 0 1 1 1 2 1 3 1 4 1 dtype: int64 Multiply two Series: 0 2 1 12 2 30 3 56 4 90 dtype: int64 Divide Series1 by Series2: 0 2.000000 1 1.333333 2 1.200000 3 1.142857 4 1.111111 dtype: float64
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer