diff --git a/lectures/polars.md b/lectures/polars.md index 3b082d4e..741528f0 100644 --- a/lectures/polars.md +++ b/lectures/polars.md @@ -544,7 +544,8 @@ As in {doc}`pandas`, Python makes it straightforward to query online databases. An important database for economists is [FRED](https://fred.stlouisfed.org/) --- a vast collection of time series data maintained by the St. Louis Fed. -Polars' `read_csv` can fetch data from a URL directly. +We download the CSV file with [requests](https://requests.readthedocs.io/en/latest/) +and pass its contents to Polars' `read_csv`. We use `try_parse_dates=True` to parse the date column automatically @@ -564,7 +565,10 @@ fred_url = ('https://fred.stlouisfed.org/graph/fredgraph.csv?' 'fgst=lin&fgsnd=2020-02-01&line_index=1&' 'transformation=lin&vintage_date=2024-07-29&' 'revision_date=2024-07-29&nd=1948-01-01') -data = pl.read_csv(fred_url, try_parse_dates=True) +import requests + +r = requests.get(fred_url) +data = pl.read_csv(r.content, try_parse_dates=True) ``` Let's inspect the first few rows