Time Series - Jupyter Notebook 2
Time Series - Jupyter Notebook 2
Along with the third-party dateutil module, you can use it to quickly perform a host of useful
functionalities on dates and times.
For example, you can manually build a date using the datetime type:
Out[1]: datetime.datetime(2015, 7, 4, 0, 0)
In [2]: #using the dateutil module, you can parse dates from a variety of string fo
Out[2]: datetime.datetime(2015, 7, 4, 0, 0)
In [4]: #Once you have a datetime object, you can do things like printing the day o
#%A- day, %w- Weekday as no..., %b-month short
In [9]: date.strftime('%w')
Out[9]: '6'
In [6]: #one of the standard string format codes for printing dates ("%A"),
#which can read in the strftime section of Python’s datetime documentation.
Out[10]: 2014-07-04 0
2014-08-04 1
2015-07-04 2
2015-08-04 3
dtype: int64
In [12]: data['2014-07-04':'2015-07-04']
Out[12]: 2014-07-04 0
2014-08-04 1
2015-07-04 2
dtype: int64
In [14]: data['2015']
Out[14]: 2015-07-04 2
2015-08-04 3
dtype: int64
In [41]: dates.to_period('D')
In [19]: #TimedeltaIndex is created, for example, when one date is subtracted from a
Out[20]: TimedeltaIndex(['0 days', '1 days', '3 days', '4 days', '5 days'], dtype
='timedelta64[ns]', freq=None)
Out[30]: TimedeltaIndex(['0 days 00:00:00', '0 days 01:00:00', '0 days 02:00:00',
'0 days 03:00:00', '0 days 04:00:00', '0 days 05:00:00',
'0 days 06:00:00', '0 days 07:00:00', '0 days 08:00:00',
'0 days 09:00:00'],
dtype='timedelta64[ns]', freq='H')
Out[31]: TimedeltaIndex(['0 days 00:00:00', '0 days 00:01:00', '0 days 00:02:00',
'0 days 00:03:00', '0 days 00:04:00', '0 days 00:05:00',
'0 days 00:06:00', '0 days 00:07:00', '0 days 00:08:00',
'0 days 00:09:00'],
dtype='timedelta64[ns]', freq='T')
#The monthly, quarterly, and annual frequencies are all marked at the end of the specified
period. Adding an S suffix to any of these marks it instead at the beginning
Out[33]: TimedeltaIndex(['0 days 00:00:00', '0 days 02:30:00', '0 days 05:00:00',
'0 days 07:30:00', '0 days 10:00:00', '0 days 12:30:00',
'0 days 15:00:00', '0 days 17:30:00', '0 days 20:00:00'],
dtype='timedelta64[ns]', freq='150T')
In [ ]: