【发布时间】:2016-12-06 23:44:19
【问题描述】:
我正在调用 API,但该 API 一次只能为我提供一年的数据。但我想使用一个循环来提取超过一年的数据。
我在一个范围内有以下开始和结束日期:
startdate = datetime.date(2011, 9, 6)
enddate = datetime.date(2014, 10, 12)
我编写了一个很长的函数(此处未显示)并使用以下代码调用该函数并传入参数:
get_hourly_WSI_latlong_historical (startdate, enddate, lat, long, fields = None)
如何在循环函数中编写下面的大段代码? ...它必须是函数格式。在下面的代码中,我希望根据我的“startdate”和“enddate”变量动态地导出这些值,而不是明确列出每个开始和结束日期上面提供。 我该怎么做?
WSI_Hourly = get_hourly_WSI_latlong_historical (datetime.date(2011, 9, 6), datetime.date(2011, 12, 31), 39.742721,-105.0816042, fields=None)
WSI_Hourly1 = get_hourly_WSI_latlong_historical (datetime.date(2012,1,1), datetime.date(2012,12,31), 39.742721,-105.0816042, fields=None)
WSI_Hourly = WSI_Hourly.append(WSI_Hourly1,ignore_index=True)
WSI_Hourly1 = get_hourly_WSI_latlong_historical (datetime.date(2013,1,1), datetime.date(2013,12,31), 39.742721,-105.0816042, fields=None)
WSI_Hourly = WSI_Hourly.append(WSI_Hourly1,ignore_index=True)
WSI_Hourly1 = get_hourly_WSI_latlong_historical (datetime.date(2014,1,1), datetime.date(2014,10,12), 39.742721,-105.0816042, fields=None)
WSI_Hourly = WSI_Hourly.append(WSI_Hourly1,ignore_index=True)
非常感谢任何帮助。
【问题讨论】:
标签: python function api loops date