Pandas: Read Timestamp from CSV in GMT then resamp

2019-08-21 17:23发布

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条回答
\"骚年 ilove
2楼-- · 2019-08-21 17:53

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().

查看更多
登录 后发表回答