I'm building a python application where I get a lot of data from various timeseries (ranging from 1 minute to 1 day). I would only like to store the times (unix timestamps) that are exactly on a whole hour (xx:00 minutes). How do I build this check?
Is a simple if timestamp % 3600 == 0: save the timestamp
sufficient enough? Or is there a better way?
10 digit epoch time format surrounded by brackets (or followed by a comma). The digits must be at the very start of the message.
It's in seconds, because time() returns a unix timestamp, which is the amount of seconds since jan 1 1970. Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), January 1, 1970.
Timestamp is the pandas equivalent of python's Datetime and is interchangeable with it in most cases. It's the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas. Value to be converted to Timestamp. Offset which Timestamp will have.
use datetime.fromtimestamp
from datetime import datetime
ts = 1415309268
cts = datetime.fromtimestamp(ts)
print(cts.minute==00)
If you want seconds also:
cts.minute==00 and cts.second==00
The timestamp is in seconds, so the time mod 3600 should be zero.
if timestamp % 3600 == 0:
# save the timestamp-value tuple
This is enough, you don't have to make a datetime object and check the minute and second for every timestamp you get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With