python-2.7unix-timestampgraphlabsframe

How to convert date from unix timestamps to human readable format in graphlab (python 2.7)


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?


Solution

  • It's a bit quirky, but you can just cast the column of unix timestamps to type "datetime.datetime" (provided you imported datetime).

    This code:

    import graphlab as gl
    import datetime as dt
    sf = gl.SFrame({'a':[1,2,3]})
    sf['a'] = sf['a'].astype(dt.datetime)
    

    Produces this:

    Columns:
        a       datetime
    
    Rows: 3
    
    Data:
    +---------------------+
    |          a          |
    +---------------------+
    | 1970-01-01 00:00:01 |
    | 1970-01-01 00:00:02 |
    | 1970-01-01 00:00:03 |
    +---------------------+
    [3 rows x 1 columns]