Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 1.08 KB

File metadata and controls

31 lines (24 loc) · 1.08 KB

Python Interface to COVID-19 Data Hub

Python csv parser csv.reader() does not seem to parse the csv well, since it cannot work with the quotation marks around strings.

However read_csv() from pandas is processing it fine.

To make a successful call, you also have to specify User-Agent header, see here, the request is hence sent separately using requests library.

Install pandas and requests by typing into terminal:

pip install pandas requests

Once installed, fetch the data:

# standard library
from io import StringIO
# nonstandard - download separately
import pandas as pd # Pandas
import requests # HTTP Request library
# download
url = "https://storage.covid19datahub.io/data-1.csv"
response = requests.get(url, headers = {"User-Agent": "Mozilla/5.0"})
# make response iterable string
data = StringIO(response.text)
# load into pandas
df = pd.read_csv(data)