gpt4 book ai didi

date - Pandas DateOffset,倒退一天

转载 作者:行者123 更新时间:2023-12-04 05:47:11 24 4
gpt4 key购买 nike

我试着理解为什么

print(pd.Timestamp("2015-01-01") - pd.DateOffset(day=1))

不会导致
pd.Timestamp("2014-12-31")

我正在使用 Pandas 0.18。我在 CET 时区运行。

最佳答案

您可以查看 pandas.tseries.offsets.DateOffset :

*kwdsTemporal parameter that add to or replace the offset value.
Parameters that add to the offset (like Timedelta):


  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds
  • microseconds
  • nanoseconds

Parameters that replace the offset value:


  • year
  • month
  • day
  • weekday
  • hour
  • minute
  • second
  • microsecond
  • nanosecond

print(pd.Timestamp("2015-01-01") - pd.DateOffset(days=1))
2014-12-31 00:00:00
另一种解决方案:
print(pd.Timestamp("2015-01-01") - pd.offsets.Day(1))
2014-12-31 00:00:00
也可以减去 Timedelta :
print(pd.Timestamp("2015-01-01") - pd.Timedelta(1, unit='d'))

关于date - Pandas DateOffset,倒退一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36764487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com