pandas 如何获得一定数量的熊猫时间戳偏移量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31031138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get pandas Timestamp offset by certain amount of months?
提问by Apogentus
Suppose I have a pandas Timestamp object t1.
假设我有一个Pandas时间戳对象 t1。
import pandas a pd
t1=pd.Timestamp('2013-04-01 00:00:00')
How can I get another pandas timestamp, offset by k months from t1?
我怎样才能得到另一个Pandas时间戳,从 t1 偏移 k 个月?
回答by EdChum
You can use relativedelta:
您可以使用relativedelta:
In [135]:
k=2
t1 + pd.datetools.relativedelta(months=k)
Out[135]:
Timestamp('2013-06-01 00:00:00')
Or DateOffset:
In [136]:
k=2
t1 + pd.DateOffset(months=k)
Out[136]:
Timestamp('2013-06-01 00:00:00')
Thanks to @AlexRiley for the suggested edit, relativedeltahas been moved to
感谢@AlexRiley 的建议编辑,relativedelta已移至
pd.offsets.relativedeltasince 0.20.0
pd.offsets.relativedelta自从 0.20.0

