How can I convert a UNIX timestamp from the input file into a human readable format?

User 3201 | 2/13/2016, 3:49:29 AM

I am working on large text file of 34gb. I have successfully parsed the file using the graphlab create. There is a column in the dataset about the date. The date is displayed in a unix timestamps. How can I convert a UNIX timestamp from the input file (converted to an SFrame) into a human readable format?

Comments

User 1592 | 2/13/2016, 10:21:33 AM

Hi Take a look here you can open the timestamp into columns.

For example, assume the column you have the UNIX timestamp is named dattime. data = data.addcolumns(data['datetime'] .splitdatetime(columnnameprefix = ''))

Will add the date fields into your SFrame data (year, month, day, hour, minute, second)

If you like to output as string

import datetime

data['string_time'] = data['timestamp'].apply(lamba x: datetime.datetime.fromtimestamp(int(x)).strftime('%Y-%m-%d %H:%M:%S'))


User 4 | 2/13/2016, 10:23:36 AM

Hi @"Paarth Sareen", if your data is in "int" datatype (the Unix timestamp is probably int?) then it can be converted to and from datetime using the operation described in this howto and its inverse.

More specifically you should be able to do something like:

import datetime sf['datetime'] = sf['datetime_as_unix_timestamp'].astype(datetime.datetime)


User 3201 | 2/14/2016, 2:15:51 AM

Thanks @Zach and @"Danny Bickson". I tried both the options. Both worked.