【发布时间】:2017-06-22 20:23:59
【问题描述】:
我有一个用来收集数据的脚本。我遇到了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()
【问题讨论】:
-
哪一行抛出异常?
-
forecasted_data.to_excel(writer, sheet_name='Sheet1')抛出异常 -
如果打印
start和end,tz属性是否可见? -
您查看过github.com/pandas-dev/pandas/issues/7056 吗?可能会有所帮助。
标签: python python-2.7 pandas datetime-format python-datetime