Create hourly/minutely time range using pandas

时间:2022-03-21 02:56:10

Is there a way to generate time range in pandas similar to date_range? something like:

有没有办法在类似于date_range的pandas中生成时间范围?就像是:

pandas.time_range("11:00", "21:30", freq="30min")

1 个解决方案

#1


37  

A time range doesn't exist as a standalone index type. Generate using a single date

时间范围不作为独立索引类型存在。使用单个日期生成

In [1]: pandas.date_range("11:00", "21:30", freq="30min")
Out[1]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-14 11:00:00, ..., 2013-07-14 21:30:00]
Length: 22, Freq: 30T, Timezone: None

The time objects

时间对象

In [2]: pandas.date_range("11:00", "21:30", freq="30min").time
Out[2]: 
array([datetime.time(11, 0), datetime.time(11, 30), datetime.time(12, 0),
       datetime.time(12, 30), datetime.time(13, 0), datetime.time(13, 30),
       datetime.time(14, 0), datetime.time(14, 30), datetime.time(15, 0),
       datetime.time(15, 30), datetime.time(16, 0), datetime.time(16, 30),
       datetime.time(17, 0), datetime.time(17, 30), datetime.time(18, 0),
       datetime.time(18, 30), datetime.time(19, 0), datetime.time(19, 30),
       datetime.time(20, 0), datetime.time(20, 30), datetime.time(21, 0),
       datetime.time(21, 30)], dtype=object)

You can also resample if you are spanning multiple dates.

如果您跨越多个日期,也可以重新取样。

What are you trying to do?

你想做什么?

#1


37  

A time range doesn't exist as a standalone index type. Generate using a single date

时间范围不作为独立索引类型存在。使用单个日期生成

In [1]: pandas.date_range("11:00", "21:30", freq="30min")
Out[1]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-14 11:00:00, ..., 2013-07-14 21:30:00]
Length: 22, Freq: 30T, Timezone: None

The time objects

时间对象

In [2]: pandas.date_range("11:00", "21:30", freq="30min").time
Out[2]: 
array([datetime.time(11, 0), datetime.time(11, 30), datetime.time(12, 0),
       datetime.time(12, 30), datetime.time(13, 0), datetime.time(13, 30),
       datetime.time(14, 0), datetime.time(14, 30), datetime.time(15, 0),
       datetime.time(15, 30), datetime.time(16, 0), datetime.time(16, 30),
       datetime.time(17, 0), datetime.time(17, 30), datetime.time(18, 0),
       datetime.time(18, 30), datetime.time(19, 0), datetime.time(19, 30),
       datetime.time(20, 0), datetime.time(20, 30), datetime.time(21, 0),
       datetime.time(21, 30)], dtype=object)

You can also resample if you are spanning multiple dates.

如果您跨越多个日期,也可以重新取样。

What are you trying to do?

你想做什么?