用法:
Series.apply(func, convert_dtype=True, args=(), **kwargs)
將標量函數應用於係列的值。
類似於 `pandas Series.apply 在係列上逐元素應用用戶定義的函數。
- func:函數
要應用的標量 Python 函數。
- convert_dtype:布爾值,默認為真
在 cuDF 中,此參數始終為 True。因為 cuDF 不支持任意對象 dtypes,所以結果將始終是由 numba 基於函數邏輯和參數類型確定的公共類型。有關詳細信息,請參閱示例。
- args:元組
不支持
- **kwargs:
不支持
參數:
注意:
UDF 緩存在內存中以避免重新編譯。第一次調用 UDF 將產生編譯開銷。
func
可能會調用用裝飾器numba.cuda.jit(device=True)
裝飾的嵌套函數,否則 numba 將引發鍵入錯誤。例子:
將基本函數應用於係列 >>> sr = cudf.Series([1,2,3]) >>> def f(x): ... return x + 1 >>> sr.apply(f) 0 2 1 3 2 4 數據類型:int64
將基本函數應用於具有空值的係列
>>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x): ... return x + 1 >>> sr.apply(f) 0 2 1 <NA> 2 4 dtype: int64
根據值是否為空,使用有條件地執行某些操作的函數
>>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x): ... if x is cudf.NA: ... return 42 ... else: ... return x - 1 >>> sr.apply(f) 0 0 1 42 2 2 dtype: int64
結果將向上轉換為從 UDF 邏輯派生的所需的公共 dtype。請注意,這意味著即使傳遞了不會導致該 dtype 的任何值的此類數據,也會返回公共類型。
>>> sr = cudf.Series([1,cudf.NA,3]) >>> def f(x): ... return x + 1.5 >>> sr.apply(f) 0 2.5 1 <NA> 2 4.5 dtype: float64
相關用法
- Python cudf.Series.applymap用法及代碼示例
- Python cudf.Series.append用法及代碼示例
- Python cudf.Series.add用法及代碼示例
- Python cudf.Series.all用法及代碼示例
- Python cudf.Series.acos用法及代碼示例
- Python cudf.Series.autocorr用法及代碼示例
- Python cudf.Series.as_mask用法及代碼示例
- Python cudf.Series.any用法及代碼示例
- Python cudf.Series.asin用法及代碼示例
- Python cudf.Series.astype用法及代碼示例
- Python cudf.Series.argsort用法及代碼示例
- Python cudf.Series.abs用法及代碼示例
- Python cudf.Series.atan用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.Series.head用法及代碼示例
- Python cudf.Series.reindex用法及代碼示例
- Python cudf.Series.interleave_columns用法及代碼示例
- Python cudf.Series.min用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.Series.apply。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。