提问人:Almodius 提问时间:8/18/2023 最后编辑:FObersteinerAlmodius 更新时间:8/18/2023 访问量:48
AssertionError:输入必须具有相同的时区 pytz。FixedOffset(-240) != 美国/New_York
AssertionError: Inputs must both have the same timezone, pytz.FixedOffset(-240) != America/New_York
问:
File1.py 将 CSV 打开为“DF”并创建一个图形。由于使用的份额是纽约市,因此时间为 -4。
df_y = pd.read_csv("Meta.csv")
df_y['Datetime'] = pd.to_datetime(df_y['Datetime'])
df_y.set_index('Datetime',inplace=True)
d = df_y.index[0]
b = df_y.index[-1]
dt_all = pd.date_range(start=d,end=b,freq='30min')
marged_index = dt_all.append(df_y.index)
timegap = marged_index[~marged_index.duplicated(keep = False)]
fig = make_subplots(rows=1, cols=1)
fig.add_ohlc(x=df_y.index,
open=df_y['Open'],
high=df_y['High'],
low=df_y['Low'],
close=df_y['Close'],
name='stock',
decreasing_line_color='#21201f',
increasing_line_color='#21201f',
row=1, col=1)
fig.update_xaxes(showgrid=False,
zeroline=False,
showticklabels=True,
showspikes=True,
spikemode='across',
spikesnap='cursor',
showline=False,
rangebreaks=[
dict(values=timegap, dvalue=1800000), # 30min:1000msec*60sec*30min
],
rangeslider_visible=False)
fig.show()
该脚本工作正常,但有第二个文件 cron.py 每 30 分钟在 Windows 操作系统中执行一次 file1.py。
from datetime import datetime
from time import sleep
import os
def main():
first = True
t_var=(1,31)
while first is True:
now = datetime.now()
if now.minute in t_var:
os.system("python3 file1.py")
sleep(80)
我的电脑在欧盟,在测试 cron.py 时显示以下错误。 在那之后,file1.py 不再独自奔跑。 我的理解是与使用的时区存在冲突。但这是在不同时区运行的两个脚本上发生的。
不幸的是,我不熟悉 python 局部变量,您能建议任何详细解释它如何工作的文档吗?Local_vars在我读过的 python 教科书中没有解释。我过去在本地设置方面遇到了其他问题,我想学习“python架构”,但不确定如何接近
重新启动 PC 后,两个脚本都工作正常(强化了我对local_var的假设)
Traceback (most recent call last):
File "C:\Program Files\Python37\Lib\site-packages\pandas\core\arrays\datetimes.py", line 2422, in _infer_tz_from_endpoints
inferred_tz = timezones.infer_tzinfo(start, end)
File "pandas\_libs\tslibs\timezones.pyx", line 328, in pandas._libs.tslibs.timezones.infer_tzinfo
AssertionError: Inputs must both have the same timezone, pytz.FixedOffset(-240) != America/New_York
The above exception was the direct cause of the following exception:
File "file1.py", line 59, in graph
dt_all = pd.date_range(start=d,end=b,freq='30min')
File "C:\Program Files\Python37\Lib\site-packages\pandas\core\indexes\datetimes.py", line 1105, in date_range
**kwargs,
File "C:\Program Files\Python37\Lib\site-packages\pandas\core\arrays\datetimes.py", line 419, in _generate_range
tz = _infer_tz_from_endpoints(start, end, tz)
) from err
TypeError: Start and end cannot both be tz-aware with different timezones
提前感谢您的帮助
答: 暂无答案
评论
pd.date_range
df_y['Datetime']
df_y['Datetime']
df_y['Datetime'] = pd.to_datetime(df_y['Datetime'], utc=True)