From df68a682109583b8a1c7a27b83dec1f284cb9546 Mon Sep 17 00:00:00 2001 From: Pratap Vardhan Date: Tue, 17 Mar 2020 20:21:35 -0400 Subject: [PATCH] UPD: covid19 valid last date column --- ...covid19-compare-country-trajectories.ipynb | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/_notebooks/2020-03-17-covid19-compare-country-trajectories.ipynb b/_notebooks/2020-03-17-covid19-compare-country-trajectories.ipynb index 130c42eb45..b812e1936a 100644 --- a/_notebooks/2020-03-17-covid19-compare-country-trajectories.ipynb +++ b/_notebooks/2020-03-17-covid19-compare-country-trajectories.ipynb @@ -61,7 +61,13 @@ "source": [ "#hide\n", "MIN_CASES = 700\n", - "countries = dff[dff['Date'].eq(dt_cols[-1]) & dff['Confirmed Cases'].ge(MIN_CASES) & \n", + "LAST_DATE = dt_cols[-1]\n", + "# sometimes last column may be empty, then go backwards\n", + "for c in dt_cols[::-1]:\n", + " if df[c].notnull().all():\n", + " LAST_DATE = c\n", + " break\n", + "countries = dff[dff['Date'].eq(LAST_DATE) & dff['Confirmed Cases'].ge(MIN_CASES) & \n", " dff['Country'].ne('China')\n", " ].sort_values(by='Confirmed Cases', ascending=False)\n", "countries = countries['Country'].values" @@ -134,7 +140,7 @@ " opacity=alt.condition(selection, alt.value(1), alt.value(0.05))\n", " )\n", " max_day = dff2['Days since 100 cases'].max()\n", - " ref = pd.DataFrame([[x, 100*1.33*(1+x)] for x in range(max_day+1)], columns=['Days since 100 cases', 'Confirmed Cases'])\n", + " ref = pd.DataFrame([[x, 100*1.3**x] for x in range(max_day+1)], columns=['Days since 100 cases', 'Confirmed Cases'])\n", " base_ref = alt.Chart(ref).encode(x='Days since 100 cases:Q', y='Confirmed Cases:Q')\n", " return (\n", " base_ref.mark_line(color='black', opacity=.5, strokeDash=[3,3]) +\n", @@ -174,12 +180,12 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "" ], "text/plain": [ @@ -247,12 +253,12 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "" ], "text/plain": [ @@ -320,12 +326,12 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "" ], "text/plain": [ @@ -393,12 +399,12 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "" ], "text/plain": [ @@ -473,12 +479,12 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "" ], "text/plain": [ @@ -552,7 +558,7 @@ "base4 = base3.transform_filter(date_filter)\n", "\n", "max_day = dff2['Days since 100 cases'].max()\n", - "ref = pd.DataFrame([[x, 100*1.33*(1+x)] for x in range(max_day+1)], columns=['Days since 100 cases', 'Confirmed Cases'])\n", + "ref = pd.DataFrame([[x, 100*1.3**x] for x in range(max_day+1)], columns=['Days since 100 cases', 'Confirmed Cases'])\n", "base_ref = alt.Chart(ref).encode(x='Days since 100 cases:Q', y='Confirmed Cases:Q')\n", "base_ref_f = base_ref.transform_filter(alt.datum['Days since 100 cases'] >= max_day)\n", "\n",