用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。