How do I download a file:
COVID-19 Data to be able to save one of its sheets named Covid-19 - Weekly occurrences
as a dataframe.
The url works if I put it in a browser.
I have tried:
import requests
import io
import pandas as pd
url = 'https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fbirthsdeathsandmarriages%2fdeaths%2fdatasets%2fweeklyprovisionalfiguresondeathsregisteredinenglandandwales%2f2020/referencetablescorrected.xlsx'
s=requests.get(url).content
df_deathsAges = pd.read_excel(io.StringIO(s.decode('utf-8')),
nrows = 25, header = 5, sheet_name='Covid-19 - Weekly occurrences')
but I get the error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 15: invalid start byte
I have tried:
url = 'https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fbirthsdeathsandmarriages%2fdeaths%2fdatasets%2fweeklyprovisionalfiguresondeathsregisteredinenglandandwales%2f2020/referencetablescorrected.xlsx'
df_deathsAges = pd.read_excel(url,'Covid-19 - Weekly occurrences')
But I get the error:
HTTPError: HTTP Error 403: Forbidden
What is the best way to proceed to accomplish this task?