python - 获取下一个时间戳值

标签 python pandas

pandas 中获取下一个时间戳值的正确解决方案是什么?

我有以下时间戳:

Timestamp('2017-11-01 00:00:00', freq='MS')

我想将此作为下一个时间戳值的结果:

Timestamp('2017-12-01 00:00:00', freq='MS')

编辑:

我正在使用多个频率(1 分钟、5 分钟、15 分钟、60 分钟、D、W-SUN、MS)。

是否有通用命令来获取下一个值?

构建一个根据每个频率运行的函数的最佳方法是吗?

最佳答案

一般解决方案是将字符串转换为偏移量并添加到时间戳:

L = ['1min', '5min', '15min', '60min', 'D', 'W-SUN', 'MS']

t = pd.Timestamp('2017-11-01 00:00:00', freq='MS')

t1 = [t + pd.tseries.frequencies.to_offset(x) for x in L]
print (t1)
[Timestamp('2017-11-01 00:01:00', freq='MS'), 
 Timestamp('2017-11-01 00:05:00', freq='MS'),
 Timestamp('2017-11-01 00:15:00', freq='MS'), 
 Timestamp('2017-11-01 01:00:00', freq='MS'),
 Timestamp('2017-11-02 00:00:00', freq='MS'), 
 Timestamp('2017-11-05 00:00:00'), 
 Timestamp('2017-12-01 00:00:00')]

关于python - 获取下一个时间戳值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409456/

相关文章:

python - 在 Pandas 中按升序和降序有条件地对单个列进行排序

python - 安装 Anaconda 后无法安装 Python 模块

python - 为什么定位 Shadow dom 元素在第 5 个元素处失败?

python - zip 生成器从元组列表传递参数

python - 如何一次性编码 Pandas 数据帧的一列?

python - Pandas value_counts() + 权重

python - 从 Pandas 数据框中删除值只出现一次的行

javascript - 如何使用scrapy中的CrawlSpider单击带有javascript onclick的链接?

python - boto3 file_upload 是否检查文件是否存在

python - 删除所有值为零的所有列