问题描述
我有一个带有纪元GMT时间戳的CSV,它以不规则的间隔与值配对.我尝试从CSV读取它,但是所有时区都转移到了本地时区.如何使其按原样(在GMT中)阅读?然后,我想以一分钟为间隔重新采样,但是,我想跳过大于用户指定值的间隙.如果无法做到这一点,是否可以将采样重采样到一分钟,但是请在空白处输入0.0之类的任意值?
I have a CSV with epoch GMT timestamp at irregular intervals paired with a value. I tried reading it from the CSV but all the times zones are shifted to my local timezone. How can I make it read in as-is (in GMT)? Then I would like the resample to one minute intervals, HOWEVER, I would like to skip gaps which are larger than a user specified value. If this is not possible, is there way to resample 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')
推荐答案
将本地日期时间转换为GMT日期时间,如下所示:
Convert local datetime to GMT datetime like this:
gmtDatetime = localdatetime - datetime.timedelta(hours=8)
时区为+08(中国).
The time zone is +08 (China).
或使用"datetime.utcfromtimestamp":
Or using 'datetime.utcfromtimestamp':
classmethod datetime.utcfromtimestamp(timestamp)
classmethod datetime.fromtimestamp(timestamp, tz=None)
这篇关于 pandas :从GMT中的CSV读取时间戳,然后重新采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!