用法:
cudf.to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, utc=None, format=None, exact=True, unit='ns', infer_datetime_format=False, origin='unix', cache=True)
将参数转换为日期时间。
- arg:int、float、str、datetime、list、tuple、一维数组、
Series DataFrame/dict-like 要转换为日期时间的对象。
- errors:{‘ignore’, ‘raise’, ‘coerce’, ‘warn’},默认 ‘raise’
- 如果‘raise’,则无效解析将引发异常。
- 如果‘coerce’,则无效解析将被设置为NaT。
- 如果‘warn’将最后的异常打印为警告和
返回输入。
- 如果‘ignore’,则无效解析将返回输入。
- dayfirst:布尔值,默认为 False
如果
arg
是 str 或其 list-likes,则指定日期解析顺序。如果为 True,则首先解析日期,例如 10/11/12 被解析为 2012-11-10。警告:dayfirst=True 并不严格,但更喜欢用 day first 解析(这是一个已知的错误,基于 dateutil 行为)。- format:str,默认无
解析时间的strftime,例如“%d/%m/%Y”,注意“%f”将一直解析到纳秒。有关选择的更多信息,请参阅 strftime 文档:https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.
- unit:str,默认 ‘ns’
arg 的单位 (D,s,ms,us,ns) 表示单位,它是整数或浮点数。这将基于原点(unix 纪元开始)。例如,使用 unit='ms' 和 origin='unix'(默认值),这将计算到 unix 纪元开始的毫秒数。
- infer_datetime_format:布尔值,默认为 False
如果 True 并且没有给出
format
,则尝试推断日期时间字符串的格式,如果可以推断,则切换到更快的解析它们的方法。在某些情况下,这可以将解析速度提高约 5-10 倍。
- datetime
如果解析成功。返回类型取决于输入: - list-like:DatetimeIndex - 系列:datetime64 dtype 的系列 - 标量:时间戳
参数:
返回:
例子:
从 DataFrame 的多列组装日期时间。键可以是常见的缩写,如 [‘year’, ‘month’, ‘day’, ‘minute’, ‘second’, ‘ms’, ‘us’, ‘ns’]) 或相同的复数
>>> import cudf >>> df = cudf.DataFrame({'year': [2015, 2016], ... 'month': [2, 3], ... 'day': [4, 5]}) >>> cudf.to_datetime(df) 0 2015-02-04 1 2016-03-05 dtype: datetime64[ns] >>> cudf.to_datetime(1490195805, unit='s') numpy.datetime64('2017-03-22T15:16:45.000000000') >>> cudf.to_datetime(1490195805433502912, unit='ns') numpy.datetime64('1780-11-20T01:02:30.494253056')
相关用法
- Python cudf.to_numeric用法及代码示例
- 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_datetime。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。