Skip to content

Commit

Permalink
Cosmetic changes to finalised demo_jt notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrauer committed Nov 9, 2023
1 parent c3bc84e commit 760658c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions notebooks/user/vbui/demo_jt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
" \"\"\"\n",
" ages = range(upper_age)\n",
" revised_rates = pd.Series(index=ages)\n",
" revised_rates.index.name = 'age'\n",
" for a in ages:\n",
" idx = next((i for i, age in enumerate(rates.index) if age > a), 0) # The zero is a trick to get the last element when one is subtracted\n",
" revised_rates.loc[a] = rates.iloc[idx - 1]\n",
Expand All @@ -74,7 +75,7 @@
" cohort_size = 100000\n",
" for a in rates.index:\n",
" lifetable[a] = cohort_size\n",
" cohort_size -= cohort_size * age_rates.loc[a]\n",
" cohort_size -= cohort_size * rates.loc[a]\n",
" return lifetable"
]
},
Expand All @@ -85,7 +86,7 @@
"outputs": [],
"source": [
"all_rates = pd.DataFrame(columns=years)\n",
"lifetables = pd.DataFrame(columns=years)\n",
"lifetables = pd.DataFrame(columns=all_rates.columns)\n",
"for year in years:\n",
" all_rates[year] = adapt_death_rates_for_lifetable(100, raw_death_rates[year])\n",
" lifetables[year] = get_lifetable_from_rates(all_rates[year])"
Expand All @@ -97,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"lifetable.plot(labels={'value': 'survivng', 'index': 'age'}, height=500, title='life table').update_layout(showlegend=False)"
"lifetables.plot(labels={'value': 'surviving'}, height=600, title='life tables by year')"
]
}
],
Expand Down

0 comments on commit 760658c

Please sign in to comment.