Fundamentals of Unix/epoch time
One may come across time values in Unix time while working with time-series data. The amount of seconds since 00:00:00 Coordinated Universal Time (UTC), Thursday, January 1, 1970, is known as Unix time, sometimes known as Epoch time. Unix time helps us decipher time stamps so we don’t get confused by time zones, daylight savings time, and other factors.
In the below example we convert epoch time to timestamp using pd.to_timestamp() method. If we want time in UTC to a particular time zone, tz_localize() and tz. convert() methods are used. In the below example we convert it to the ‘Europe/Berlin’ timezone.
Python3
# importing pandas import pandas as pd from datetime import datetime # epoch time epoch = 1598776989 # converting to timestamp timestamp = pd.to_datetime(epoch, unit = 's' ) print (timestamp) # converting it to a particular time zone print (timestamp.tz_localize( 'UTC' ).tz_convert( 'Europe/Berlin' )) |
Output:
2020-08-30 08:43:09 2020-08-30 10:43:09+02:00
Manipulating Time Series Data in Python
A collection of observations (activity) for a single subject (entity) at various time intervals is known as time-series data. In the case of metrics, time series are equally spaced and in the case of events, time series are unequally spaced. We may add the date and time for each record in this Pandas module, as well as fetch dataframe records and discover data inside a specific date and time range.
Contact Us