首页 > 解决方案 > 如何将时间戳四舍五入到最接近的秒数?

问题描述

请帮助我将此时间戳四舍五入到秒我有数据帧索引是时间戳的系列,如下所示。如何将索引四舍五入到最接近的秒数?

Timestamp('2019-06-16 07:53:32.961000')

预期结果

Timestamp('2019-06-16 07:53:33')

标签: pythonpandas

解决方案


使用Timestamp.round

pd.Timestamp('2019-06-16 07:53:32.961000').round('s')
# Timestamp('2019-06-16 07:53:33')

推荐阅读