Federal Debt Over Time
Tags:
import urllib.request
from pathlib import Path
import altair as alt
import pandas as pd
url = "https://fiscaldata.treasury.gov/static-data/HstDebt_all_years.csv.zip"
local_file = Path(Path(url).name)
if not local_file.exists():
with urllib.request.urlopen(url) as req:
resp = req.read()
local_file.write_bytes(resp)
df = pd.read_csv(local_file, parse_dates=["Record Date"])
df.head(5)
Record Date | Debt Outstanding Amount | Source Line Number | Fiscal Year | Fiscal Quarter Number | Calendar Year | Calendar Quarter Number | Calendar Month Number | Calendar Day Number | |
---|---|---|---|---|---|---|---|---|---|
0 | 1790-01-01 | 71060508.50 | 1 | 1790 | 2 | 1790 | 1 | 1 | 1 |
1 | 1791-01-01 | 75463476.52 | 1 | 1791 | 2 | 1791 | 1 | 1 | 1 |
2 | 1792-01-01 | 77227924.66 | 1 | 1792 | 2 | 1792 | 1 | 1 | 1 |
3 | 1793-01-01 | 80358634.04 | 1 | 1793 | 2 | 1793 | 1 | 1 | 1 |
4 | 1794-01-01 | 78427404.77 | 1 | 1794 | 2 | 1794 | 1 | 1 | 1 |
alt.Chart(df).mark_line().encode(
x=alt.X("Fiscal Year", axis = alt.Axis(format=("d"))),
y="Debt Outstanding Amount",
)