移动 pandas 日期时间索引
我猜这是一个非常愚蠢的问题,但无论如何,这里是:
我有一个带有日期时间索引的数据框,如下所示:
DatetimeIndex(['1995-01-02', '1995-01-03', '1995-01-04', '1995-01-05',
'1995-01-06', '1995-01-09', '1995-01-10', '1995-01-11',
'1995-01-12', '1995-01-13'])
毫不奇怪,time
字段是“00:00: 00":
bets.index.map(pd.datetime.time)
给出:
Index([00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00,
00:00:00, 00:00:00, 00:00:00])
我想将所有索引元素的时间字段设置为其他内容(例如中午)。最简单的方法是什么?
This is a really stupid question, I am guessing, but anyway, here goes:
I have a dataframe with a datetime index which looks like this:
DatetimeIndex(['1995-01-02', '1995-01-03', '1995-01-04', '1995-01-05',
'1995-01-06', '1995-01-09', '1995-01-10', '1995-01-11',
'1995-01-12', '1995-01-13'])
Not too surprisingly, the time
field is "00:00:00":
bets.index.map(pd.datetime.time)
gives:
Index([00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00, 00:00:00,
00:00:00, 00:00:00, 00:00:00])
I would like to set the time field to something else (e.g., noon), for all the index elements. What is the simplest way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIUC,您可以使用
to_timedelta
并传入所需的小时数:输出:
IIUC, you could use
to_timedelta
and pass in the required number of hours:Output: