Series的计算
1. Series.add(other, level=None, fill_value=None)
 
Series加法:+
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.add(t)
a    1.0
b    2.0
c    NaN
d    NaN
e    NaN
f    8.0
g    NaN
h    NaN
dtype: float64
>>> s.add(t,fill_value=0)
a    1.0
b    2.0
c    2.0
d    3.0
e    4.0
f    8.0
g    6.0
h    1.0
dtype: float64
 
2. Series.sub(other, level=None, fill_value=None)
 
Series减法:-
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.sub(t)
a   -1.0
b    0.0
c    NaN
d    NaN
e    NaN
f    2.0
g    NaN
h    NaN
dtype: float64
>>> s.sub(t,fill_value=0)
a   -1.0
b    0.0
c    2.0
d    3.0
e    4.0
f    2.0
g    6.0
h   -1.0
dtype: float64
 
3. Series.mul(other, level=None, fill_value=None)
 
Series乘法:*
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.mul(t)
a     0.0
b     1.0
c     NaN
d     NaN
e     NaN
f    15.0
g     NaN
h     NaN
dtype: float64
>>> s.mul(t,fill_value=0)
a     0.0
b     1.0
c     2.0
d     3.0
e     4.0
f    15.0
g     6.0
h     1.0
dtype: float64
 
4. Series.div(other, level=None, fill_value=None)
 
Series除:/
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.div(t)
a    0.000000
b    1.000000
c         NaN
d         NaN
e         NaN
f    1.666667
g         NaN
h         NaN
dtype: float64
>>> s.div(t,fill_value=1)
a    0.000000
b    1.000000
c    2.000000
d    3.000000
e    4.000000
f    1.666667
g    6.000000
h    1.000000
dtype: float64
 
5. Series.floordiv(other, level=None, fill_value=None)
 
Series除://
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.floordiv(t)
a    0.0
b    1.0
c    NaN
d    NaN
e    NaN
f    1.0
g    NaN
h    NaN
dtype: float64
>>> s.floordiv(t,fill_value=1)
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    1.0
g    6.0
h    1.0
dtype: float64
 
6. Series.mod(other, level=None, fill_value=None)
 
Series求余:%
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.mod(t)
a    0.0
b    0.0
c    NaN
d    NaN
e    NaN
f    2.0
g    NaN
h    NaN
dtype: float64
>>> s.mod(t,fill_value=1)
a    0.0
b    0.0
c    0.0
d    0.0
e    0.0
f    2.0
g    0.0
h    0.0
dtype: float64
 
7. Series.pow(other, level=None, fill_value=None)
 
Series幂:%
 参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.pow(t)
a      0.0
b      1.0
c      NaN
d      NaN
e      NaN
f    125.0
g      NaN
h      NaN
dtype: float64
>>> s.mod(t,fill_value=1)
a      0.0
b      1.0
c      2.0
d      3.0
e      4.0
f    125.0
g      6.0
h      1.0
dtype: float64
 
8. Series.combine(other, func, fill_value=None)
 
使用函数子联合两个Series
 参数:
other: Series or scalar valuefun: function
将两个常数所为函数的参数,返回结果fill_value: None or float value, default None
在计算之前,用于填充缺失值。
>>> s = pd.Series(data=np.arange(7), dtype=np.float32, index=list('abcdefg'))
>>> s
a    0.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
dtype: float32
>>> t = pd.Series({'a':1, 'b':1, 'd':np.NaN, 'f':3, 'h':1})
>>> t
a    1.0
b    1.0
d    NaN
f    3.0
h    1.0
dtype: float64
>>> s.combine(t, max)
a    1.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
h    NaN
dtype: float64
>>> s.mod(t, max, fill_value=1)
a    1.0
b    1.0
c    2.0
d    3.0
e    4.0
f    5.0
g    6.0
h    1.0
dtype: float64
 
9. Series.round(decimals=0)
 
使用函数子联合两个Series
 参数:
decimals: int, default 0: 要舍入的小数位数。
>>> s = pd.Series([1.2, 2.46, 3.7])
>>> s
0    1.20
1    2.46
2    3.70
dtype: float64
>>> s1.round(decimals=1)
0    1.2
1    2.5
2    3.7
dtype: float64
 
10. 布尔运算:
Series.lt(other, level, fill_value): <Series.gt(other, level, fill_value): >Series.le(other, level, fill_value): <=Series.ge(other, level, fill_value): >=Series.ne(other, level, fill_value): !=Series.eq(other, level, fill_value): =
参数:
other: Series or scalar valuefill_value: None or float value, default None
在计算之前,用于填充缺失值。level: int or name
>>> s = pd.Series([1, 3, 4, 2, 7, 0, 8], index=list('abcdefg'))
>>> t = pd.Series([1, 2, 4, 3, 6, 1, 8], index=list('abcdefg'))
>>> s.lt(t)
a    False
b    False
c    False
d     True
e    False
f     True
g    False
dtype: bool
>>> s.eq(t)
a     True
b    False
c     True
d    False
e    False
f    False
g     True
dtype: bool
>>> s.ge(t)
a     True
b     True
c     True
d    False
e     True
f    False
g     True
dtype: bool









