有一个带有纬度/经度支持的免费历史天气数据API吗?

6
我想提取一些国家(更具体地说,某些国家的省/州)的历史天气数据,通过纬度/经度,需要将结果作为.csv文件或pandas数据框。我尝试了forecast.io / DarkSky的包装器(https://zeevgilovitz.com/python-forecast.io/),但每天请求限制为1000次。因此,我想知道是否有任何免费API支持纬度/经度请求,并以pandas数据框或.csv格式返回结果?以下是我尝试过的内容(如果您只需要每天1000个请求,则也可以使用)。
lat = 30
lng = 5
start_date = datetime.datetime(2016, 1, 1)
attributes = ["temperature", "humidity", "pressure", "windSpeed"]


def getWeatherData(lat, lng, start_date, attributes):

    times = []
    data = {}

    for attr in attributes:
        data[attr] = []

    for offset in range(1, 1000):
        forecast = forecastio.load_forecast(api_key, lat, lng, time=start_date+datetime.timedelta(offset), units="us")
        h = forecast.hourly()
        d = h.data

        for p in d:
            times.append(p.time)
            for attr in attributes:
                data[attr].append(p.d[attr])

    weather_data = pd.DataFrame(data, index=times)

    return weather_data

CSV/DF格式是硬性要求,还是你只需要Pandas可以读取的东西? - igrolvr
1个回答

2
https://openweathermap.org/price网站提供了一些免费的API计划,如果您每天需要少于1000次调用,则可能足够使用。
该API不会以csv或DataFrame格式返回数据,但pandas可以处理其返回的json格式。
示例:
import requests
import json
import pandas as pd

url = 'https://api.openweathermap.org/data/2.5/onecall?lat=33.44&lon=-94.04&exclude=hourly,minutely&appid=<api_key_hidden>'
data = requests.get(url).json()

df = pd.DataFrame.from_dict(data['daily'])

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接