如何使用cudf.Series.applymap()?

时间:2019-08-13 16:15:31

标签: series rapids cudf

有人可以提供一些在cuDF系列上如何使用applymap方法的示例吗?

下面是从文档中复制的,here是文档的链接。

applymap(self, udf, out_dtype=None)
  Apply a elemenwise function to transform the values in the Column.

  The user function is expected to take one argument and return the result, which will be stored to the output Series. The function cannot reference globals except for other simple scalar objects.

  Parameters
    udf : function
      Wrapped by `numba.cuda.jit` for call on the GPU as a device function.

    out_dtype : numpy.dtype; optional
      The dtype for use in the output. By default, the result will have the same dtype as the source.

  Returns
    result: Series
      The mask and index are preserved.

1 个答案:

答案 0 :(得分:0)

API文档中有一个使用最新版本https://rapidsai.github.io/projects/cudf/en/0.9.0/10min.html#Applymap中的applymap的示例:

def add_ten(num):
    return num + 10

print(df['a'].applymap(add_ten))

通常,您传递一个期望对标量进行操作的函数,该函数将JIT编译为矢量化的GPU代码,并针对Series中的每个元素在GPU上执行。