My application involves dealing with data (contained in a CSV) which is of the following form:
Epoch (number of seconds since Jan 1, 1970), Value
1368431149,
Convert them to datetime64[s]
:
np.array([1368431149, 1368431150]).astype('datetime64[s]')
# array([2013-05-13 07:45:49, 2013-05-13 07:45:50], dtype=datetime64[s])
You can also use Pandas DatetimeIndex like so
pd.DatetimeIndex(df['timestamp']*10**9)
the *10**9
puts it into the format it's expecting for such timestamps.
This is nice since it allows you to use functions such as .date()
or .tz_localize()
on the series.
You can also use pandas to_datetime:
df['datetime'] = pd.to_datetime(df["timestamp"], unit='s')
This method requires Pandas 0.18 or later.