gpt4 book ai didi

python - 类型错误 : Timestamp subtraction

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:00 29 4
gpt4 key购买 nike

我有一个脚本可以收集数据。我遇到了 TypeError: Timestamp subtraction must have the same timezones or no timezones 错误。我查看了有关此错误的其他帖子,但找不到适合我的解决方案。

我怎样才能绕过这个错误。收集数据后,我不会对其进行操作,我不太明白为什么我不能将此 dataframe 保存到 excel 文档中。谁能提供帮助?

import pandas as pd
import numpy as np
import os
import datetime
import pvlib
from pvlib.forecast import GFS, NAM

#directories and filepaths
barnwell_dir = r'D:\Saurabh\Production Forecasting\Machine Learning\Sites\Barnwell'
barnwell_training = r'8760_barnwell.xlsx'

#constants
writer = pd.ExcelWriter('test' + '_PythonExport.xlsx', engine='xlsxwriter')
time_zone = 'Etc/GMT+5'
barnwell_list = [r'8760_barnwell.xlsx', 33.2376, -81.3510]

def get_gfs_processed_data1():
start = pd.Timestamp(datetime.date.today(), tz=time_zone) #used for testing last week
end = start + pd.Timedelta(days=6)
gfs = GFS(resolution='quarter')
#get processed data for lat/long point
forecasted_data = gfs.get_processed_data(barnwell_list[1], barnwell_list[2], start, end)
forecasted_data.to_excel(writer, sheet_name='Sheet1')


get_gfs_processed_data1()

最佳答案

当我运行您的示例代码时,我在堆栈跟踪的末尾收到来自 XlsxWriter 的以下警告:

"Excel doesn't support timezones in datetimes. "
TypeError: Excel doesn't support timezones in datetimes.
Set the tzinfo in the datetime/time object to None or use the
'remove_timezone' Workbook() option

我认为这是不言自明的。要从时间戳中去除时区,请按照建议传递 remove_timezone 选项:

writer = pd.ExcelWriter('test' + '_PythonExport.xlsx',
engine='xlsxwriter',
options={'remove_timezone': True})

当我进行此更改时,示例会运行并生成一个 xlsx 文件。请注意,remove_timezone 选项需要 XlsxWriter >= 0.9.5。

关于python - 类型错误 : Timestamp subtraction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44708735/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com