当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python cudf.Series.divide用法及代码示例


用法:

Series.divide(other, level=None, fill_value=None, axis=0)

获取数据帧或系列和其他元素的浮点数除法(二元运算符truediv)。

等效于 frame / other ,但支持用 fill_value 替换其中一个输入中的缺失数据。使用反向版本 rtruediv

参数

other标量、序列、系列或数据帧

任何单元素或多元素数据结构,或list-like 对象。

axis整数或字符串

系列仅支持0,数据帧支持1columns

fill_value浮点数或无,默认无

在计算之前使用此值填充现有的缺失 (NaN) 值以及成功对齐 DataFrame 所需的任何新元素。如果两个相应的 DataFrame 位置中的数据都丢失,则结果将丢失。

返回

DataFrame或Series

算术运算的结果。

例子

DataFrame

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.truediv(10)
           angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df.div(10)
           angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df / 10
           angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0

Series

>>> import cudf
>>> a = cudf.Series([1, 10, 20, None], index=['a', 'b', 'c', 'd'])
>>> a
a       1
b      10
c      20
d    <NA>
dtype: int64
>>> b = cudf.Series([1, None, 2, None], index=['a', 'b', 'd', 'e'])
>>> b
a       1
b    <NA>
d       2
e    <NA>
dtype: int64
>>> a.truediv(b, fill_value=0)
a     1.0
b     Inf
c     Inf
d     0.0
e    <NA>
dtype: float64

相关用法


注:本文由纯净天空筛选整理自rapids.ai大神的英文原创作品 cudf.Series.divide。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。