问题
I have a CSV with epoch GMT timestamp at irregular intervals paired with a value. I tried reading in from the CSV but all the times are shifted to my local timezone. How do I have it just read in as-is (in GMT)? Then I would like the resample to one minute intervals, HOWEVER, I would like to be able to have it skip gaps which are larger than a user specified value. If this is not possible, is there way to resample to to one minute, but in the gaps, put in an arbitrary value like 0.0?
Data:
Time,Data
1354979750250,0.2343
1354979755250,2.3433
1354979710250,1.2343
def date_utc(s):
return parse(s, tzinfos=tzutc)
x = read_csv("time2.csv", date_parser=date_utc, converters={'Time': lambda x:datetime.fromtimestamp(int(x)/1000.)}).set_index('Time')
回答1:
Convert local datetime to GMT datetime like this:
gmtDatetime = localdatetime - datetime.timedelta(hours=8)
The time zone is +08 (China).
Or using 'datetime.utcfromtimestamp':
classmethod datetime.utcfromtimestamp(timestamp)
classmethod datetime.fromtimestamp(timestamp, tz=None)
Return the UTC datetime corresponding to the POSIX timestamp, with tzinfo None. This may raise OverflowError, if the timestamp is out of the range of values supported by the platform C gmtime() function, and OSError on gmtime() failure. It’s common for this to be restricted to years in 1970 through 2038. See also fromtimestamp().
来源:https://stackoverflow.com/questions/14371476/pandas-read-timestamp-from-csv-in-gmt-then-resample