Downloading a dataset from Eurostat it’s easy, let’s start:
- Click the link of inflation: https://ec.europa.eu/eurostat/databrowser/explore/all/economy?lang=en&subtheme=prc.prc_hicp&display=list&sort=category&extractionId=prc_hicp_manr. It looks like the following image
note: at the end of the link is the code of the dataset
2. on the shaded area and downloading symbol we copy the link
3. we set the following cell (python)
# Set the URL and directory where you want to save the dataset
url = 'https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/prc_hicp_manr?format=TSV&compressed=true'
eurostat_code = "prc_hicp_manr"
directory_path = 'your_location'
4. the following block code is a function where it downloads the eurostat_code, decompesses the file, removes the older one, and if it’s needed makes the directory_path which is set by you above.
import os
import gzip
import urllib.request
def download_eurostat_dataset(dataset):
# Ensure the directory exists, create it if it doesn't
if not os.path.exists(directory_path):
os.makedirs(directory_path)
out_file = os.path.join(directory_path, dataset + ".tsv")
# Remove the existing file if it exists
if…
Learn more How to download a dataset from Eurostat with python
