用法:
cudf.to_numeric(arg, errors='raise', downcast=None)
將參數轉換為數值類型。
- arg:column-convertible
要轉換為數字類型的對象
- errors:{‘raise’, ‘ignore’, ‘coerce’},默認 ‘raise’
解析期間處理錯誤的策略。
- ‘raise’ 將通知用戶遇到的所有錯誤。
- ‘ignore’ 將跳過錯誤並返回
arg
。 - ‘coerce’ 會將無效值保留為空值。
- downcast:{‘integer’, ‘signed’, ‘unsigned’, ‘float’},默認無
如果設置,將嘗試將down-convert 解析結果的數據類型設為可能的最小類型。對於每個
downcast
類型,此方法將從以下集合中確定可能的最小 dtype:- {‘integer’, ‘signed’}:所有大於或等於
np.int8
的整數類型 - {‘unsigned’}:所有大於或等於
np.uint8
的無符號類型 - {‘float’}:所有大於或等於
np.float32
的浮點類型
請注意,向下轉換行為與解析解耦。無論
errors
參數如何,都會引發向下轉換期間遇到的錯誤。- {‘integer’, ‘signed’}:所有大於或等於
- 係列或ndarray
根據輸入,如果傳入series,則返回series,否則返回ndarray
參數:
返回:
注意:
與 pandas 的一個重要區別是此函數不接受混合的數字/非數字類型序列。例如
[1, 'a']
。接收到此類輸入時將引發TypeError
,無論errors
參數如何。例子:
>>> s = cudf.Series(['1', '2.0', '3e3']) >>> cudf.to_numeric(s) 0 1.0 1 2.0 2 3000.0 dtype: float64 >>> cudf.to_numeric(s, downcast='float') 0 1.0 1 2.0 2 3000.0 dtype: float32 >>> cudf.to_numeric(s, downcast='signed') 0 1 1 2 2 3000 dtype: int16 >>> s = cudf.Series(['apple', '1.0', '3e3']) >>> cudf.to_numeric(s, errors='ignore') 0 apple 1 1.0 2 3e3 dtype: object >>> cudf.to_numeric(s, errors='coerce') 0 <NA> 1 1.0 2 3000.0 dtype: float64
相關用法
- Python cudf.to_datetime用法及代碼示例
- Python cudf.testing.testing.assert_series_equal用法及代碼示例
- Python cudf.testing.testing.assert_index_equal用法及代碼示例
- Python cudf.testing.testing.assert_frame_equal用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.core.column.string.StringMethods.endswith用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.DataFrame.mod用法及代碼示例
- Python cudf.DataFrame.isin用法及代碼示例
- Python cudf.core.column.string.StringMethods.title用法及代碼示例
- Python cudf.DataFrame.rmul用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.DatetimeIndex.dayofweek用法及代碼示例
- Python cudf.DataFrame.apply用法及代碼示例
- Python cudf.core.column.string.StringMethods.contains用法及代碼示例
- Python cudf.core.column.string.StringMethods.rsplit用法及代碼示例
- Python cudf.DataFrame.exp用法及代碼示例
- Python cudf.Series.head用法及代碼示例
- Python cudf.DataFrame.drop用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.to_numeric。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。