Created
May 20, 2020 10:00
-
-
Save LowriWilliams/7251719aae49eba09e37793f998ba3b0 to your computer and use it in GitHub Desktop.
corona/line_graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe srcdoc=\"\n", | |
" <!-- Load Charts.js -->\n", | |
" <script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js'></script>\n", | |
" \n", | |
" <canvas id='chart'></canvas>\n", | |
" <script>\n", | |
" var ctx = document.getElementById('chart').getContext('2d');\n", | |
" ctx.canvas.width = 800 - (.1 * 800);\n", | |
" ctx.canvas.height = 420 - (.15 * 420);\n", | |
" var myNewChart = new Chart(ctx,{ type: 'line', data: {\n", | |
" 'labels': [\n", | |
" '2020-01-22',\n", | |
" '2020-01-23',\n", | |
" '2020-01-24',\n", | |
" '2020-01-25',\n", | |
" '2020-01-26',\n", | |
" '2020-01-27',\n", | |
" '2020-01-28',\n", | |
" '2020-01-29',\n", | |
" '2020-01-30',\n", | |
" '2020-01-31',\n", | |
" '2020-02-01',\n", | |
" '2020-02-02',\n", | |
" '2020-02-03',\n", | |
" '2020-02-04',\n", | |
" '2020-02-05',\n", | |
" '2020-02-06',\n", | |
" '2020-02-07',\n", | |
" '2020-02-08',\n", | |
" '2020-02-09',\n", | |
" '2020-02-10',\n", | |
" '2020-02-11'\n", | |
" ],\n", | |
" 'datasets': [\n", | |
" {\n", | |
" 'data': [\n", | |
" 555,\n", | |
" 653,\n", | |
" 941,\n", | |
" 2019,\n", | |
" 2794,\n", | |
" 4473,\n", | |
" 6057,\n", | |
" 7783,\n", | |
" 9776,\n", | |
" 11374,\n", | |
" 14549,\n", | |
" 17295,\n", | |
" 20588,\n", | |
" 24503,\n", | |
" 24630,\n", | |
" 30806,\n", | |
" 31471,\n", | |
" 37488,\n", | |
" 40472,\n", | |
" 42632,\n", | |
" 44982\n", | |
" ],\n", | |
" 'label': 'Confirmed',\n", | |
" 'borderColor': '#FFCE00'\n", | |
" },\n", | |
" {\n", | |
" 'data': [\n", | |
" 0,\n", | |
" 18,\n", | |
" 26,\n", | |
" 56,\n", | |
" 80,\n", | |
" 107,\n", | |
" 132,\n", | |
" 170,\n", | |
" 213,\n", | |
" 259,\n", | |
" 305,\n", | |
" 362,\n", | |
" 426,\n", | |
" 492,\n", | |
" 494,\n", | |
" 634,\n", | |
" 638,\n", | |
" 813,\n", | |
" 910,\n", | |
" 1013,\n", | |
" 1115\n", | |
" ],\n", | |
" 'label': 'Deaths',\n", | |
" 'borderColor': '#E63029'\n", | |
" },\n", | |
" {\n", | |
" 'data': [\n", | |
" 0,\n", | |
" 30,\n", | |
" 36,\n", | |
" 49,\n", | |
" 54,\n", | |
" 63,\n", | |
" 110,\n", | |
" 133,\n", | |
" 187,\n", | |
" 252,\n", | |
" 340,\n", | |
" 487,\n", | |
" 644,\n", | |
" 899,\n", | |
" 1029,\n", | |
" 1487,\n", | |
" 1763,\n", | |
" 2701,\n", | |
" 3312,\n", | |
" 3950,\n", | |
" 4781\n", | |
" ],\n", | |
" 'label': 'Recovered',\n", | |
" 'borderColor': '#007849'\n", | |
" }\n", | |
" ]\n", | |
"}, options: null });\n", | |
" </script>\n", | |
" \" src=\"\" width=\"800\" height=\"420\" frameborder=0 sandbox=\"allow-scripts\"></iframe>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Group the rows by their date and sum the values of the confirmed cases, deaths and recovered cases\n", | |
"\n", | |
"df_dates = df.groupby(['Date'])[['Confirmed', 'Deaths', 'Recovered']].sum().reset_index()\n", | |
"\n", | |
"# Put the result in a dataframe\n", | |
"\n", | |
"df_dates = pd.DataFrame(df_dates)\n", | |
"\n", | |
"import iplotter\n", | |
"\n", | |
"data = { \n", | |
" 'labels': df_dates['Date'].astype(str).tolist(),\n", | |
" 'datasets': [{ \n", | |
" 'data': df_dates['Confirmed'].values.tolist(),\n", | |
" 'label': \"Confirmed\",\n", | |
" 'borderColor': \"#FFCE00\"\n", | |
" }, { \n", | |
" 'data': df_dates['Deaths'].values.tolist(),\n", | |
" 'label': \"Deaths\",\n", | |
" 'borderColor': \"#E63029\"\n", | |
" },\n", | |
" { \n", | |
" 'data': df_dates['Recovered'].values.tolist(),\n", | |
" 'label': \"Recovered\",\n", | |
" 'borderColor': \"#007849\"\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"\n", | |
"chart_js = iplotter.ChartJSPlotter()\n", | |
"chart_js.plot(data, chart_type=\"line\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment