Browse Source

Plotly

pull/79/head
Jure Šorn 4 years ago
parent
commit
ddb303f2ae
5 changed files with 6422 additions and 7 deletions
  1. 2
      README.md
  2. 2
      index.html
  3. 2814
      web/covid_cases.js
  4. 3603
      web/covid_deaths.js
  5. 8
      web/update_plots.py

2
README.md

@ -3367,7 +3367,7 @@ continents = pd.read_csv('https://datahub.io/JohnSnowLabs/country-and-continent-
df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code') df = pd.merge(covid, continents, left_on='iso_code', right_on='Three_Letter_Country_Code')
df = df.groupby(['Continent_Name', 'date']).sum().reset_index() df = df.groupby(['Continent_Name', 'date']).sum().reset_index()
df['Total Deaths per Million'] = df.total_deaths * 1e6 / df.population df['Total Deaths per Million'] = df.total_deaths * 1e6 / df.population
df = df[('2020-03-14' < df.date) & (df.date < '2020-06-25')]
df = df[('2020-03-14' < df.date) & (df.date < '2020-10-22')]
df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns') df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns')
line(df, x='Date', y='Total Deaths per Million', color='Continent').show() line(df, x='Date', y='Total Deaths per Million', color='Continent').show()
``` ```

2
index.html

@ -2858,7 +2858,7 @@ continents = pd.read_csv(<span class="hljs-string">'https://datahub.io/JohnSnowL
df = pd.merge(covid, continents, left_on=<span class="hljs-string">'iso_code'</span>, right_on=<span class="hljs-string">'Three_Letter_Country_Code'</span>) df = pd.merge(covid, continents, left_on=<span class="hljs-string">'iso_code'</span>, right_on=<span class="hljs-string">'Three_Letter_Country_Code'</span>)
df = df.groupby([<span class="hljs-string">'Continent_Name'</span>, <span class="hljs-string">'date'</span>]).sum().reset_index() df = df.groupby([<span class="hljs-string">'Continent_Name'</span>, <span class="hljs-string">'date'</span>]).sum().reset_index()
df[<span class="hljs-string">'Total Deaths per Million'</span>] = df.total_deaths * <span class="hljs-number">1e6</span> / df.population df[<span class="hljs-string">'Total Deaths per Million'</span>] = df.total_deaths * <span class="hljs-number">1e6</span> / df.population
df = df[(<span class="hljs-string">'2020-03-14'</span> &lt; df.date) &amp; (df.date &lt; <span class="hljs-string">'2020-06-25'</span>)]
df = df[(<span class="hljs-string">'2020-03-14'</span> &lt; df.date) &amp; (df.date &lt; <span class="hljs-string">'2020-10-22'</span>)]
df = df.rename({<span class="hljs-string">'date'</span>: <span class="hljs-string">'Date'</span>, <span class="hljs-string">'Continent_Name'</span>: <span class="hljs-string">'Continent'</span>}, axis=<span class="hljs-string">'columns'</span>) df = df.rename({<span class="hljs-string">'date'</span>: <span class="hljs-string">'Date'</span>, <span class="hljs-string">'Continent_Name'</span>: <span class="hljs-string">'Continent'</span>}, axis=<span class="hljs-string">'columns'</span>)
line(df, x=<span class="hljs-string">'Date'</span>, y=<span class="hljs-string">'Total Deaths per Million'</span>, color=<span class="hljs-string">'Continent'</span>).show() line(df, x=<span class="hljs-string">'Date'</span>, y=<span class="hljs-string">'Total Deaths per Million'</span>, color=<span class="hljs-string">'Continent'</span>).show()
</code></pre></div> </code></pre></div>

2814
web/covid_cases.js
File diff suppressed because it is too large
View File

3603
web/covid_deaths.js
File diff suppressed because it is too large
View File

8
web/update_plots.py

@ -8,11 +8,12 @@ from datetime import date, time, datetime, timedelta
import pandas as pd import pandas as pd
from plotly.express import line from plotly.express import line
import plotly.graph_objects as go import plotly.graph_objects as go
import re
def main(): def main():
print('Updating covid deaths...')
update_covid_deaths()
# print('Updating covid deaths...')
# update_covid_deaths()
print('Updating covid cases...') print('Updating covid cases...')
update_confirmed_cases() update_confirmed_cases()
@ -88,7 +89,8 @@ def update_confirmed_cases():
def update_file(filename, figure): def update_file(filename, figure):
lines = read_file(filename) lines = read_file(filename)
out = lines[:6] + [f' {figure.to_json()}\n', ' )\n', '};\n']
f_json = figure.to_json(pretty=True).replace('\n', '\n ')
out = lines[:6] + [f' {f_json}\n', ' )\n', '};\n']
write_to_file(filename, out) write_to_file(filename, out)

Loading…
Cancel
Save