O'Reilly logo

Mastering pandas for Finance by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating time-series with specific frequencies

Time-series data in pandas can also be created to represent intervals of time other than daily frequency. Different frequencies can be generated with pd.date_range() by utilizing the freq parameter. This parameter defaults to a value of D, which represents daily frequency.

To introduce the creation of nondaily frequencies, the following command creates a DatetimeIndex with one-minute intervals using freq='T':

In [20]:
   bymin = pd.Series(np.arange(0, 90*60*24),
                     pd.date_range('2014-08-01', 
                                   '2014-10-29 23:59:00',
                                   freq='T'))
   bymin

Out[20]:
   2014-08-01 00:00:00         0
   2014-08-01 00:01:00         1
   2014-08-01 00:02:00         2
                           ...  
   2014-10-29 23:57:00    129597
   2014-10-29 23:58:00    129598
   2014-10-29 23:59:00    129599

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required