dask.dataframe.DataFrame.to_timestamp
dask.dataframe.DataFrame.to_timestamp¶
- DataFrame.to_timestamp(freq=None, how='start', axis=0)[源代码]¶
- 将时间戳转换为 DatetimeIndex,位于周期的 开始。 - 此文档字符串是从 pandas.core.frame.DataFrame.to_timestamp 复制而来的。 - Dask 版本可能存在一些不一致性。 - 参数
- 频率str, PeriodIndex 的默认频率
- 期望的频率。 
- 如何{‘s’, ‘e’, ‘start’, ‘end’}
- 转换周期为时间戳的约定;周期开始与周期结束。 
- 轴{0 或 ‘index’, 1 或 ‘columns’}, 默认 0
- 要转换的轴(默认是索引)。 
- 复制bool, 默认 True (Dask 不支持)
- 如果为 False,则不会复制底层输入数据。 - 备注 - copy 关键字将在 pandas 3.0 中改变行为。写时复制 将被默认启用,这意味着所有带有 copy 关键字的方法将使用延迟复制机制来推迟复制并忽略 copy 关键字。copy 关键字将在未来版本的 pandas 中被移除。 - 您已经可以通过启用写时复制 - pd.options.mode.copy_on_write = True来获得未来的行为和改进。
 
- 返回
- DataFrame
- DataFrame 具有一个 DatetimeIndex。 
 
 - 示例 - >>> idx = pd.PeriodIndex(['2023', '2024'], freq='Y') >>> d = {'col1': [1, 2], 'col2': [3, 4]} >>> df1 = pd.DataFrame(data=d, index=idx) >>> df1 col1 col2 2023 1 3 2024 2 4 - 在这种情况下,生成的时间戳将是一年之初的时间。 - >>> df1 = df1.to_timestamp() >>> df1 col1 col2 2023-01-01 1 3 2024-01-01 2 4 >>> df1.index DatetimeIndex(['2023-01-01', '2024-01-01'], dtype='datetime64[ns]', freq=None) - 使用 freq,它是时间戳将具有的偏移量 - >>> df2 = pd.DataFrame(data=d, index=idx) >>> df2 = df2.to_timestamp(freq='M') >>> df2 col1 col2 2023-01-31 1 3 2024-01-31 2 4 >>> df2.index DatetimeIndex(['2023-01-31', '2024-01-31'], dtype='datetime64[ns]', freq=None)