python - Unable to get proper timestamp ranges -
i hoping generate range of timestamps between:
18:00 (est) on oct 6th, 2014
and same time 400 seconds later interval size of 2.2
seconds.
when following:
start_time = datetime.datetime(year = 2014, month = 10, day = 6, hr = 18, tzinfo = pytz.timezone('us/eastern')) end_time = start_time + datetime.timedelta(seconds=400)
something seems fail:
start_time.isoformat()
returns '2014-10-06t18:06:40-04:56'
end_time.isoformat()
returns '2014-10-06t18:06:40-04:56'
note time-zone offset both timestamps above are: -04:56
(4 hours , 56 minutes) though est 5 hours behind utc. ?
moving forward, if seek range of timestamps between these 2 dates every 2.2 seconds
(i.e. 2200 ms
):
ts = pd.date_range(start=start_time, end=end_time, freq='2200l')
i get:
> ts[0] timestamp('2014-10-06 18:56:00-0400', tz='us/eastern', offset='2200l')
or in other words:
> ts[0].isoformat() '2014-10-06t18:56:00-04:00'
which not create sense (note time 18:56
, though asking range between 18:00
, 18:06:40
(i.e. 400
seconds after 18:00
)
i got tired of dealing python's awkward datetime implementation (particularly respect timezones), , have started using crsmithdev.com/arrow. solution using lib:
import arrow start_time = arrow.get(2014, 10, 6, tzinfo='us/eastern') end_time = start_time.replace(seconds=400) print start_time.isoformat() print end_time.isoformat() # alternate form start_time = arrow.get('2014-10-06t18:00:00.000-04:00') end_time = start_time.replace(seconds=400) print start_time.isoformat() print end_time.isoformat() # datetime arrow object start_time_dt = start_time.datetime
python pandas
No comments:
Post a Comment