Aliases for time series frequencies

To specify offsets, a number of aliases are available; some of the most commonly used ones are as follows:

  • B, BM: This stands for business day, business month. These are the working days of the month, that is, any day that is not a holiday or a weekend.
  • D, W, M, Q, A: This stands for calendar day, week, month, quarter, and year end.
  • H, T, S, L, U: This stands for hour, minute, second, millisecond, and microsecond.

These aliases can also be combined. In the following case, we resample every 7 minutes and 30 seconds:

    In [267]: googTickTS.resample('7T30S').head(5)
    Out[267]:
                               close     high   low   open    volume  
    tstamp
    2014-05-27 09:30:00-04:00 556.8266 557.4362 556.3144 556.8800 28075.0
    2014-05-27 09:37:30-04:00 556.5889 556.9342 556.4264 556.7206 11642.9
    2014-05-27 09:45:00-04:00 556.9921 557.2185 556.7171 556.9871  9800.0
    2014-05-27 09:52:30-04:00 556.1824 556.5375 556.0350 556.3896 14350.0
    2014-05-27 10:00:00-04:00 555.2111 555.4368 554.8288 554.9675 12512.5
    5 rows x 5 columns

Suffixes can be applied to the frequency aliases to specify when in frequency period to start. These are known as anchoring offsets:

  • W – SUN, MON, ... example: W-TUE indicates a weekly frequency starting on a Tuesday.
  • Q – JAN, FEB, ... DEC example: Q-MAY indicates a quarterly frequency with the year end in May.
  • A – JAN, FEB, ... DEC example: A-MAY indicates an annual frequency with the year end in May.

These offsets can be used as arguments for the date_range and bdate_range functions, as well as constructors for index types such as PeriodIndex and DatetimeIndex. A comprehensive discussion on this can be found in the pandas documentation at http://pandas.pydata.org/pandas-docs/stable/timeseries.html#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset