pandas 日期偏移:pd.DateOffset()

1、功能

pd.DateOffset() 是用于处理日期和时间偏移的类。它可以用于在日期和时间上添加或减去一定的偏移量,例如天数、小时、分钟等,以生成新的日期时间。

pd.DateOffset() 生成的是新的日期时间对象,原始的日期时间对象并不会被修改。

ps:这个很好用哦,我经常用

2、语法

pd.DateOffset(),参数

  • days: 添加或减去的天数。
  • months: 添加或减去的月数。
  • years: 添加或减去的年数。
  • weeks: 添加或减去的周数。
  • hours: 添加或减去的小时数。
  • minutes: 添加或减去的分钟数。
  • seconds: 添加或减去的秒数。
  • microseconds: 添加或减去的微秒数。

3、示例

import pandas as pd
from datetime import datetime

start_date = datetime.now()

print(start_date) # 2023-08-26 20:18:33.496518


# 使用 DateOffset 添加 5 天
new_date = start_date + pd.DateOffset(days=5)

print(new_date) # 2023-08-31 20:18:33.496518

发表评论

评论列表,共 1 条评论

  • nytonguesthouse.co.uk

    I'm not sure why but this weblog is loading very slow for me. Is anyone else having this problem or is it a issue on my end? I'll check back later on and see if the problem still exists.