1

I want to create a date_range with pandas that spans a whole year, have a frequency of 1min but only span from 9:30 to 16:00 every day

If I do like this:

rng = pd.date_range('2012-01-01', '2013-01-01', freq="1min")

...I get all 24 hours in the days. I only want from 9:30 to 16:00...

4

1 回答 1

1

如果您希望此间隔也在端点处关闭/打开,您可以指定一些选项。

In [7]: rng
Out[7]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 00:00:00, ..., 2013-01-01 00:00:00]
Length: 527041, Freq: T, Timezone: None

In [8]: rng[rng.indexer_between_time('9:30','16:00')]
Out[8]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01 09:30:00, ..., 2012-12-31 16:00:00]
Length: 143106, Freq: None, Timezone: None
于 2013-10-09T18:39:49.930 回答