Even if you have no use for time series in general, you may still find the Date class contained in the module quite useful.
Defines an object that combines some date- and/or time-related information with a given frequency. The frequency can be pictured as the unit into which the date is expressed.
In practice, Date objects are stored internally as integers. The conversion to integers and back is controlled by the frequency. For example, a Date object with a daily frequency corresponds to the gregorian proleptic date, the number of days since January 1st, 1AD; a Date with a monthly frequency corresponds to the number of months since January 1AD, and so forth.
Several options are available to construct a Date object explicitly. In each case, the frequency must be specified with the freq argument. Valid frequency specifications are listed in the Frequency constants section.
Give appropriate values to any of the year, month, day, quarter, hour, minute or second arguments.
>>> ts.Date(freq='Q',year=2004,quarter=3) <Q : 2004Q3> >>> ts.Date(freq='D',year=2001,month=1,day=1) <D : 01-Jan-2001>
Note that there is only need to specify as much information as is relevant depending on the frequency. In the example above, there was no need to give a day input parameter with a quarterly frequency 'Q'.
Use the string keyword. This method uses a modified version of the mx.DateTime parser sub-module. More information is available in its documentation.
>>> ts.Date('D', string='2007-01-01') <D : 01-Jan-2007>
>>> ts.Date('D', datetime=datetime.datetime(2007, 1, 1, 17, 0)) <D : 01-Jan-2007>
Use the value keyword and provide an integer representation of the date.
>>> ts.Date('D', value=732677) <D : 01-Jan-2007> >>> ts.Date('M', value=(12*2008+6)) <M : Jun-2009> >>> ts.Date('Y', value=2007) <A-DEC : 2008>
>>> yesterday = ts.now('D') - 1 >>> infivemonths = ts.now('M') + 5
>>> Y = ts.Date('A', year=2007) >>> Y_beg = Y.asfreq('D', relation='START') >>> Y_end = Y.asfreq('D', relation='END') >>> days_in_year = (Y_end - Y_beg + 1) >>> days_in_year 365
Returns the integer coding the Date object. This attribute is read-only.
>>> ts.Date('D','2001-01-01').value 730486
The following attributes are read-only, with an integer type.
||Quarter Year (1)||...|
||Day of the month||[1-31]|
||Day of the week, starting Monday||[0-6]|
||Day of the year, starting Jan-01||[1-366]|
|Date.strftime (format)||Returns a string representation of the instance, according to format.|
|Date.toordinal ()||Returns the proleptic Gregorian date as an ordinal.|
|Date.asfreq (freq)||Returns a new Date object with frequency freq.|
Two convenience functions are provided to access the current date: