- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试导入一些时间序列数据并将其转换为 UTC,以便我可以将其与另一个数据集合并。此数据似乎有 24 小时数据且没有 DST 调整。 This post给出了类似的答案,但他们只是放弃了这一行。我需要移动它,以便我可以将它与我的其他数据合并。
当我运行我的代码时:
df = pd.read_csv('http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2010/data/hourly/{}/{}_{}_solar.csv'.format(723898,723898,1998), usecols=["YYYY-MM-DD", "HH:MM (LST)","Meas Glo (Wh/m^2)","Meas Dir (Wh/m^2)","Meas Dif (Wh/m^2)"])
def clean_time(obj):
hour = int(obj[0:-3])
hour = str(hour - 1)
if len(str(hour)) == 2:
return hour+":00"
else:
return "0" + hour + ":00"
df['HH:MM (LST)'] = df['HH:MM (LST)'].apply(clean_time)
df['DateTime'] = df['YYYY-MM-DD'] + " " + df['HH:MM (LST)']
df = df.set_index(pd.DatetimeIndex(df['DateTime']))
df.drop(["YYYY-MM-DD", "HH:MM (LST)",'DateTime'],axis=1,inplace=True)
df.index = df.index.tz_localize('US/Pacific', ambiguous='infer')
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 1998-10-25 01:00:00 as there are no repeated times
pytz.exceptions.NonExistentTimeError: 1998-04-05 02:00:00
最佳答案
最小复制场景:
from datetime import datetime, timedelta
import pandas as pd
df = pd.DataFrame([[datetime(2019, 10, 27, 0) + timedelta(hours=i), i] for i in range(24)], columns=['dt', 'i']).set_index('dt')
df.index.tz_localize('Europe/Amsterdam', ambiguous='infer')
pytz.exceptions.AmbiguousTimeError: Cannot infer dst time from 2019-10-27 02:00:00 as there are no repeated times
解决方案:手动指定哪些日期时间对象必须被视为 DT(夏令时)或 DST(夏令时)。另见: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.tz_localize.html
from datetime import datetime, timedelta
import numpy as np
import pandas as pd
df = pd.DataFrame([[datetime(2019, 10, 27, 0) + timedelta(hours=i), i] for i in range(24)], columns=['dt', 'i']).set_index('dt')
infer_dst = np.array([False] * df.shape[0]) # all False -> every row considered DT, alternative is True to indicate DST. The array must correspond to the iloc of df.index
df.index.tz_localize('Europe/Amsterdam', ambiguous=infer_dst) # no error
关于 python , Pandas : tz_localize AmbiguousTimeError: Cannot infer dst time with non DST dates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36757981/
我正在尝试转换 csv 文件中时间/日期列(“Created_At”)中“GMT”时间的所有实例,以便它全部采用“EST”格式。请看下面: import pandas as pd from panda
为什么这个“pythonic”代码在 tz_localize() 行上不起作用? import pandas as pd df = pd.DataFrame([{ "Localtime":"2016-
在 python pandas 中,我有一个如下所示的数据集: 对于2007-04-26 17:00:00之前的数据,时区是美国/东部。对于之后的数据,时区是美国/芝加哥。 当我运行这个时: data
'此错误仅发生在某些股票上,例如 NFLX、KO 或 MCD,但 AAPL 或 INFy yfinance 为 0.1.63 和 0.1.69,pandas 1.2.3 或 1.4 时不会发生' im
引用:Python pandas convert unix timestamp with timezone into datetime 搜索过这个主题,但仍然找不到答案。 我有一个数据框,格式如下:
我有一个时间序列,它是由带有时钟的传感器测量的,该时钟不根据 DST 规则进行调整。因此,日期时间数据与 DST 无关。在 Pandas 中本地化这些数据的最佳方法是什么? 最佳答案 您可以先本地化到
我想用 pandas tz_localize 本地化一个日期时间系列。该系列跨越 DST 日期(例如,德国 CET 为 25Oct2015)。我通常这样做 import pandas as pd T
我正在尝试导入一些时间序列数据并将其转换为 UTC,以便我可以将其与另一个数据集合并。此数据似乎有 24 小时数据且没有 DST 调整。 This post给出了类似的答案,但他们只是放弃了这一行。我
我是一名优秀的程序员,十分优秀!