Add, subtract, multiple and divide two Pandas Series
Last Updated :
28 Jul, 2020
Let us see how to perform basic arithmetic operations like addition, subtraction, multiplication, and division on 2 Pandas Series.
For all the 4 operations we will follow the basic algorithm :
- Import the
Pandas
module.
- Create 2 Pandas Series objects.
- Perform the required arithmetic operation using the respective arithmetic operator between the 2 Series and assign the result to another Series.
- Display the resultant Series.
Addition of 2 Series
import pandas as pd
series1 = pd.Series([ 1 , 2 , 3 , 4 , 5 ])
series2 = pd.Series([ 6 , 7 , 8 , 9 , 10 ])
series3 = series1 + series2
print (series3)
|
Output :
Subtraction of 2 Series
import pandas as pd
series1 = pd.Series([ 1 , 2 , 3 , 4 , 5 ])
series2 = pd.Series([ 6 , 7 , 8 , 9 , 10 ])
series3 = series1 - series2
print (series3)
|
Output :
Multiplication of 2 Series
import pandas as pd
series1 = pd.Series([ 1 , 2 , 3 , 4 , 5 ])
series2 = pd.Series([ 6 , 7 , 8 , 9 , 10 ])
series3 = series1 * series2
print (series3)
|
Output :
Division of 2 Series
import pandas as pd
series1 = pd.Series([ 1 , 2 , 3 , 4 , 5 ])
series2 = pd.Series([ 6 , 7 , 8 , 9 , 10 ])
series3 = series1 / series2
print (series3)
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...