如何从Pandas DataFrame.Index whos对象的类型为datetime.time的时间中添加/减去时间(小时,分钟等)? [英] How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time?

查看:141
本文介绍了如何从Pandas DataFrame.Index whos对象的类型为datetime.time的时间中添加/减去时间(小时,分钟等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataFrame,其索引仅为datetime.time,并且在DataFrame.Index和datetime.time中没有方法来移动时间. datetime.time已替换,但仅适用于系列的单个项目吗?

I've got a DataFrame who's index is just datetime.time and there's no method in DataFrame.Index and datetime.time to shift the time. datetime.time has replace but that'll only work on individual items of the Series?

这是使用的索引的示例:

Here's an example of the index used:

In[526]:  dfa.index[:5]
Out[526]: Index([21:12:19, 21:12:20, 21:12:21, 21:12:21, 21:12:22], dtype='object')

In[527]:  type(dfa.index[0])
Out[527]: datetime.time

推荐答案

利亚姆(Liam)的链接看起来不错,但也可以查看pandas.Timedelta-看起来可以很好地与NumPy和Python的时间增量配合使用.

Liam's link looks great, but also check out pandas.Timedelta - looks like it plays nicely with NumPy's and Python's time deltas.

https://pandas.pydata.org/pandas-docs/stable/timedeltas.html

pd.date_range('2014-01-01', periods=10) + pd.Timedelta(days=1)

这篇关于如何从Pandas DataFrame.Index whos对象的类型为datetime.time的时间中添加/减去时间(小时,分钟等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆