两个Pandas系列的加、减、乘、除法
让我们看看如何在2个Pandas系列上进行基本的算术运算,如加法、减法、乘法和除法。
对于所有4个操作,我们将遵循基本的算法。
1.导入Pandas模块。
2.创建2个Pandas系列对象。
3.使用2个系列之间各自的算术运算符进行所需的算术运算,并将结果分配给另一个系列。
4.显示结果系列。
增加2个系列
# importing the module
import pandas as pd
# creating 2 Pandas Series
series1 = pd.Series([1, 2, 3, 4, 5])
series2 = pd.Series([6, 7, 8, 9, 10])
# adding the 2 Series
series3 = series1 + series2
# displaying the result
print(series3)
输出 :
2系列的减法
# importing the module
import pandas as pd
# creating 2 Pandas Series
series1 = pd.Series([1, 2, 3, 4, 5])
series2 = pd.Series([6, 7, 8, 9, 10])
# subtracting the 2 Series
series3 = series1 - series2
# displaying the result
print(series3)
输出 :
2系列的乘法
# importing the module
import pandas as pd
# creating 2 Pandas Series
series1 = pd.Series([1, 2, 3, 4, 5])
series2 = pd.Series([6, 7, 8, 9, 10])
# multiplying the 2 Series
series3 = series1 * series2
# displaying the result
print(series3)
输出 :
2系列的分部
# importing the module
import pandas as pd
# creating 2 Pandas Series
series1 = pd.Series([1, 2, 3, 4, 5])
series2 = pd.Series([6, 7, 8, 9, 10])
# dividing the 2 Series
series3 = series1 / series2
# displaying the result
print(series3)
输出 :