Home » Pandas Datetime

Pandas Datetime

The Pandas can provide the features to work with time-series data for all domains. It also consolidates a large number of features from other Python libraries like scikits.timeseries by using the NumPy datetime64 and timedelta64 dtypes. It provides new functionalities for manipulating the time series data.

The time series tools are most useful for data science applications and deals with other packages used in Python.

Example1:

Output:

DatetimeIndex(['2013-05-04 00:00:00', '2013-05-04 00:00:01',                 '2013-05-04 00:00:02', '2013-05-04 00:00:03',                 '2013-05-04 00:00:04', '2013-05-04 00:00:05',                 '2013-05-04 00:00:06', '2013-05-04 00:00:07'],                dtype='datetime64[ns]', freq='S')  

Example2:

You can pass errors=’ignore’ if the date does not meet the timestamp. It will return the original input without raising any exception.

If you pass errors=’coerce’, it will force an out-of-bounds date to NaT.

Output:

Timestamp('1800-07-06 00:00:00')  

Example3:

Output:

DatetimeIndex(['2017-06-04 00:00:00',                  '2017-06-04 00:00:01',                 '2017-06-04 00:00:02',                 '2017-06-04 00:00:03',                 '2017-06-04 00:00:04'],                 dtype='datetime64[ns]', freq='S')  

Example4:

Output:

DatetimeIndex(['2017-06-04 00:00:00+00:00', '2017-06-04 00:00:01+00:00',                 '2017-06-04 00:00:02+00:00',                  '2017-06-04 00:00:03+00:00',                 '2017-06-04 00:00:04+00:00'],                dtype='datetime64[ns, UTC]', freq='S')  

Example5:

Output:

DatetimeIndex(['2017-06-04 00:00:00', '2017-06-04 00:00:01',                 '2017-06-04 00:00:02', '2017-06-04 00:00:03',                 '2017-06-04 00:00:04'],          dtype='datetime64[ns]', freq='S')  

Next TopicPandas Time Offset

You may also like