[英]For half-hourly intervals can I use Pandas TimeDeltaIndex, PeriodIndex or DateTimeIndex?
I have a table of data values that should be indexed with half-hourly intervals, and I've been processing them with Pandas and Numpy. 我有一个数据值表,应该以半小时为间隔编制索引,并且我一直在用Pandas和Numpy处理它们。 Currently they're in CSV files and I import them using
read_csv
to a dataframe with only the interval-endpoint as an index. 当前它们在CSV文件中,我使用
read_csv
将它们导入到仅以时间间隔端点为索引的数据帧中。 I am uncomfortable with that and want to have the intervals themselves as the index. 我对此感到不舒服,并希望将间隔本身作为索引。
I do not know whether to use a DateTimeIndex
, a PeriodIndex
or a TimedeltaIndex
... All of them seem very similar in practice, to me. 我不知道是否要使用
DateTimeIndex
, PeriodIndex
或TimedeltaIndex
...在我看来,它们在实践中都非常相似。 My operations include 我的操作包括
Can Pandas even do all of these? 熊猫能做到所有这些吗? Is it advisable?
这是明智的吗? I already am using this interval library , would using Pandas
tslib
and period
be better? 我已经在使用此时间间隔库 ,使用Pandas
tslib
和period
会更好吗?
if you only need a series with time interval of 30 minutes you can do this: 如果您只需要时间间隔为30分钟的系列,则可以执行以下操作:
import pandas as pd
import datetime as dt
today = dt.datetime.date()
yesterday = dt.datetime.date()-dt.timedelta(days=1)
time_range = pd.date_range(yesterday,today, freq='30T')
now you could use it to set an index such has 现在您可以使用它来设置索引
pd.DataFrame(0, index=time_range,columns=['yourcol'])
Out[35]:
yourcol
2016-09-25 00:00:00 0
2016-09-25 00:30:00 0
2016-09-25 01:00:00 0
2016-09-25 01:30:00 0
2016-09-25 02:00:00 0
this would be a DateTimeIndex 这将是一个DateTimeIndex
you can read more about time interval in pandas here: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases 您可以在此处了解有关熊猫时间间隔的更多信息: http : //pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.