用法:
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。