a Weather API

Debmalya Pramanik
2 min readMar 8, 2021

Often it is very difficult to get your hands on real-world data, which is a great burden for any machine learning or deep learning experts/beginners who are looking forward to getting their hands dirty. Well, (considering this my first medium-post) I thought of sharing a Weather API which is available for free (and yes, paid versions too)!

Weather API: Plans and an Introduction

Looking for real weather data, I stumbled across visualcrossing, an amazing website that provides Forecast and Historical Weather Data. The free plan allows up to 1000 calls a day (i.e. at one go you can get near about 3 years of data) and the paid plans as below.

visual-crossing Paid Plans

Fetching the JSON Data (using Python)

Well, python is all you need in your system to fetch the JSON format data. I’ve created a GitHub-Gist that can fetch the data (for India) and store it as a JSON file. The code is available here at this link. Initial code pre-processing using pandas can be done as follows.

ignoreColumns = ["datetimeEpoch", "stations", "source", "hours"]data = pd.DataFrame(data["days"])
data["datetime"] = data["datetime"].apply(
lambda x : pd.to_datetime(x, format = "%Y-%m-%d", errors = "coerce")
)
data = data[[column for column in data.columns if column not in ignoreColumns]]

Considering data as the name of the variable which was used to fetch the data, the data frame is generated nicely.

DataFrame

Disclaimer

I’m using the free version of the API to get about 5–10 years of data and use it to devise a machine learning model.

Hopefully, I will be able to post the model with an explanation in my next post.

--

--

Debmalya Pramanik
0 Followers

An AI-ML practitioner, with a knack of playing games and photography!