gpt4 book ai didi

python - Darksky 循环一年的每日数据 - 日期时间错误

转载 作者:行者123 更新时间:2023-12-01 06:22:36 25 4
gpt4 key购买 nike

我尝试使用预报循环遍历 2019 年的每日天气数据,但错误不断显示。不确定是什么问题。

import pandas as pd 
import requests
import json
from forecastiopy import *
from datetime import date, timedelta, datetime
import datetime

key = 'xxxxx'

city = [40.730610, -73.935242]
start = datetime.datetime(2019, 1, 1)


for day in range(1,365):
fio = ForecastIO.ForecastIO(key,
units=ForecastIO.ForecastIO.UNITS_SI,
lang=ForecastIO.ForecastIO.LANG_ENGLISH,
latitude=city[0],
longitude=city[1],
time=start+datetime.timedelta(day))
daily = FIODaily.FIODaily(fio)
print ('Max Temperature', daily.get_day(day)['temperatureMax'])
print ('Min Temperature:', daily.get_day(day)['temperatureMin'])
print ('Precipitation Pobability:', daily.get_day(day)['precipProbability'])
print ('Precipitation Intensity', daily.get_day(day)['precipIntensity'])

下面显示的错误。

enter image description here

最佳答案

ForecastIO.ForecastIO(key,
...,
time=start+datetime.timedelta(day))

这里,time 参数应该是一个直接映射到 Dark Sky API 的字符串。 :

time

Either be a UNIX time (that is, seconds since midnight GMT on 1 Jan 1970) or a string formatted as follows: [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone]. [...]

因此,您可以使用 isoformat() 格式化 datetime 对象。

ForecastIO.ForecastIO(key,
...,
time=(start+datetime.timedelta(day)).isoformat())

关于python - Darksky 循环一年的每日数据 - 日期时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60289915/

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