pandas中的加减乘除和比较大小运算

import pandas as pd
money=pd.Series([100,20,None])
money-15
Out[4]: 
0    85.0
1     5.0
2     NaN
dtype: float64
# do substraction with - operator, missing values are ignored
# the .sub method allows you to specify a 'fill_value' parameter to use in place of missing values
money.sub(15,fill_value=0)
Out[7]: 
0    85.0
1     5.0
2   -15.0
dtype: float64
# some explanation:
# Python interprets the score*2.5 expression as score._mul_(2.5)
#._mul_() is a special method that always begin and end with two underscores
# so, they also are called `dunder` methods as the method that implements
# the operator is surrounded by double underscores (dunder, 'double underscores')

pandas中的加减乘除和比较大小运算_第1张图片

pandas中的加减乘除和比较大小运算_第2张图片
值得注意的是,这里仅限于数值型Series的运算。
如果是字符串就不能这么简单地比较了。

你可能感兴趣的:(python数据处理恩仇录,pandas,加减运算,比较运算)