The method .timestamp()only works with Python 3.3 . If you are using an older version of Python, you will need to calculate it directly:
import datetime
import numpy as np
to_timestamp = np.vectorize(lambda x: (x - datetime.datetime(1970, 1, 1)).total_seconds())
from_timestamp = np.vectorize(lambda x: datetime.datetime.utcfromtimestamp(x))
hist, bin_edges = np.histogram(to_timestamp(dates))
print hist, from_timestamp(bin_edges)
alexw source
share