Fetch Weather and Climate Data with MeteoStat Open-Source Python Library

An easy and robust solution for data science and machine learning applications

Amit Chauhan

--

Photo by Alex Chumak on Unsplash

Meteostat is an open-source python library for fetching weather and climate data around the globe, the data is based on the open interface from governments.

To install the library in the environment


pip install meteostat
# importing the library 
from datetime import datetime
import matplotlib.pyplot as plt
from meteostat import Point, Daily
# setting the start and end time
start = datetime(2023, 1, 1)
end = datetime(2023, 12, 31)

The point method is used to fetch the weather and climate data from any location. The arguments passed in this method are latitude and longitude.

# fetching point data from New Delhi
New_Delhi = Point(28.654667138557485, 77.23127697641567)
# using the start and end date for data
data = Daily(New_Delhi, start, end)
data = data.fetch()
# visualizing the line chart of temperature 
data.plot(y=['tavg', 'tmin', 'tmax'])
plt.show()

Output:

Output of temperature. An image by the Author
# Import Meteostat library
from meteostat import Point

# Create Point New Delhi
New_Delhi = Point(28.654667138557485, 77.23127697641567, 60)
print(New_Delhi)

We can also get to know the nearest weather station location based on the coordinates.

# importing the station method
from meteostat import Stations

# creating an instance of the station class
stations = Stations()

# using the nearby method from the station class
stations = stations.nearby(28.654667138557485, 77.23127697641567)

# fetching one information of weather station
station = stations.fetch(1)

print(station)

Output:

Output parameters. An image by the Author

--

--