i have text file many rows of data - first piece of data in each row unix timestamp such 1436472000. using numpy.loadtxt , in parameters converters want specify convert timestamp whatever numpy understands date time. know needs go after 0: in curly brackets, can't work out how convert it. know converter can used matplotlib.dates.strpdate2num normal dates, won't work unix timestamps.
code:
timestamp, closep, highp, lowp, openp, volume = np.loadtxt(filename,delimiter=",",unpack=true,converters={ 0: }) thanks in advance, please ask if me clarify mean.
while converters can convenient, slow because called once each row of data. faster convert data after timestamps loaded numpy array of integers:
x = np.array([1436472000, 1436472001]) x = np.asarray(x, dtype='datetime64[s]') yields array of numpy datetime64s:
array(['2015-07-09t16:00:00-0400', '2015-07-09t16:00:01-0400'], dtype='datetime64[s]') to obtain python datetime.datetimes use tolist():
>>> x.tolist() # [datetime.datetime(2015, 7, 9, 20, 0), # datetime.datetime(2015, 7, 9, 20, 0, 1)] as know, matplotlib datenums count number of days since 0001-01-01 00:00:00 utc, plus one. these not timestamps (which count seconds since epoch, 1970-01-01 00:00:00 utc):
>>> matplotlib.dates.date2num(x.tolist()) # array([ 735788.83333333, 735788.83334491])
Comments
Post a Comment