Is there a free historic weather data API with Latitude / Longitude support?

2.6k views Asked by At

I want to extract (free) historic weather data for some countries (more specificaly the provinces / states in some countries) via latitude / longitude and I need the results as a .csv file or pandas data frame. I tried the wrapper for forecast.io / DarkSky (https://zeevgilovitz.com/python-forecast.io/) but it is limited to 1000 requests per day. So i was wondering if there is any API that is free, returns a pandas data frame or .csv format and that supports langitude / longitude requests?

Here is what I tried (and what is also working if you only want 1000 requests per day).

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
1

There are 1 answers

0
igrolvr On

https://openweathermap.org/price has an API with some free plans that might be enough if you need < 1000 calls per day

It doesn't return data in csv or DataFrame formats, but pandas can handle the json format it returns

Example:

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'])