0

I have a dataset that I am trying to manipulate in GraphLab. I want to convert a UNIX Epoch timestamp from the input file (converted to an SFrame) into a human readable format so I can do analysis based on hour of day and day of week.

time_array is the column/feature of the SFrame sf representing the timestamp, I have broken out just the EPOCH time to simplify things. I know how to convert the time of one row, but I want a vector operation. Here is what I have for one row.

time_array = sf['timestamp']

datetime.datetime.fromtimestamp(time_array[0]).strftime('%Y-%m-%d %H')
Mayank Patel
  • 3,868
  • 10
  • 36
  • 59

3 Answers3

1

You can also get parts of the time from the timestamp to create another column, by which to filter (e.g., get the hour):

sf['hour'] = [x.strftime('%H')for x in sf['timestamp']]
Nicole Goebel
  • 537
  • 1
  • 9
  • 17
0

So after staring at this for awhile and then posting the question it came to me, hopefully someone else can benefit as well. Use the .apply method with the datetime.datetime() function

sf['date_string'] = sf['timestamp'].apply(lambda x:    datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d %H'))
GMB
  • 337
  • 2
  • 6
  • 21
  • You can also get parts of the time from the timestamp to create another column, by which to filter (e.g., get the hour): sf['hour'] = [x.strftime('%H')for x in sf['timestamp']] – Nicole Goebel Mar 18 '16 at 22:27
0

you can also use the split_datetime API to split the timestamp to multiple columns:

split_datetime('timestamp',limit=['hour','minute'])
Allan Ruin
  • 5,229
  • 7
  • 37
  • 42