import pandas as pd s1 = pd.Series([1, 2, 3], index=["a", "b", "c"]) s2 = pd.Series([4, 5, 6], index=["a", "b", "c"]) s3 = s1.add(s2) print(s3)
a 5 b 7 c 9 dtype: int64
import pandas as pd s1 = pd.Series([1, 2, 3], index=["a", "b", "c"]) s2 = pd.Series([4, 5, 6], index=["b", "c", "d"]) s3 = s1.add(s2, fill_value=0) print(s3)
a 1 b 6 c 8 d 6 dtype: int64The code examples above use the pandas library package. The import statement in each example is importing the pandas library and renaming it as 'pd' for convenience.