Covid-19 in the World

curl https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv > /shared/positive.csv
curl https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv > /shared/deaths.csv
2.3s
Bash in Python
import pandas as pd
import plotly.graph_objs as go
def process_data(filename):
  data = pd.read_csv(filename)
  del data['Lat']
  del data['Long']
  df = data.groupby('Country/Region').sum().T
  df['date'] = pd.to_datetime(df.index)
  return df
def incremental_data(data):
  d = data-data.shift();
  d = d.drop(d.index[0])
  d['date']=data['date']
  return d;
def rolling(data,window):
  df = data.rolling(window).mean()
  df['date'] = pd.to_datetime(df.index)
  return df[(window-1):]
def plot_data(data,incremental=False,last=90,window=0,log_scale=False):
  if incremental:
    data = incremental_data(data)
  if window > 0:
    data = rolling(data,window)
  if last > 0:
    data = data[-last:]
  fig =go.Figure(data=[
    go.Scatter(mode='lines',name='Italy', x=data['date'], y=data['Italy'], marker_color='magenta'),
    go.Scatter(mode='lines',name='Greece', x=data['date'], y=data['Greece'], marker_color='lightskyblue'),
    go.Scatter(mode='lines',name='France', x=data['date'], y=data['France'], marker_color='dodgerblue'),
    #go.Scatter(mode='lines',name='China', x=data['date'], y=data['China'], marker_color='red'),
    go.Scatter(mode='lines',name='Austria', x=data['date'], y=data['Austria'], marker_color='red'),
    #go.Scatter(mode='lines',name='US', x=data['date'], y=data['US'], marker_color='blue'),
    go.Scatter(mode='lines',name='Germany', x=data['date'], y=data['Germany'], marker_color='black'),
    go.Scatter(mode='lines',name='Spain', x=data['date'], y=data['Spain'], marker_color='darkgreen'),
   #go.Scatter(mode='lines',name='Brazil', x=data['date'], y=data['Brazil'], marker_color='limegreen'),
   #go.Scatter(mode='lines',name='India', x=data['date'], y=data['India'], marker_color='green'),
    go.Scatter(mode='lines',name='Switzerland', x=data['date'], y=data['Switzerland'], marker_color='darkred'),
    go.Scatter(mode='lines',name='Netherlands', x=data['date'], y=data['Netherlands'], marker_color='orange'),
    go.Scatter(mode='lines',name='UK', x=data['date'], y=data['United Kingdom'], marker_color='pink')])
  if log_scale:
    fig.update_yaxes(type="log")
  return fig
  
df = process_data('/shared/positive.csv')
df2 = process_data('/shared/deaths.csv')
df.sort_values(by=['date'], ascending=False)
1.8s
Python

Europe

New cases

plot_data(df,incremental=True,window=7)
3.0s
Python

New deaths

plot_data(df2,incremental=True,window=7)
1.2s
Python

Outside Europe

def plot_data2(data,incremental=False,last=0,window=0,log_scale=False):
  if incremental:
    data = incremental_data(data)
  if window > 0:
    data = rolling(data,window)
  if last > 0:
    data = data[-last:]
  fig =go.Figure(data=[
    go.Scatter(mode='lines',name='Italy', x=data['date'], y=data['Italy'], marker_color='magenta'),
    go.Scatter(mode='lines',name='China', x=data['date'], y=data['China'], marker_color='red'),
    go.Scatter(mode='lines',name='US', x=data['date'], y=data['US'], marker_color='blue'),
    go.Scatter(mode='lines',name='Brazil', x=data['date'], y=data['Brazil'], marker_color='limegreen'),
    go.Scatter(mode='lines',name='Canada', x=data['date'], y=data['Canada'], marker_color='darkred'),
    go.Scatter(mode='lines',name='Japan', x=data['date'], y=data['Japan'], marker_color='orange'),
    go.Scatter(mode='lines',name='India', x=data['date'], y=data['India'], marker_color='green'),
    go.Scatter(mode='lines',name='Mexico', x=data['date'], y=data['Mexico'], marker_color='darkgreen'),
    go.Scatter(mode='lines',name='UK', x=data['date'], y=data['United Kingdom'], marker_color='pink')
  ])
  if log_scale:
    fig.update_yaxes(type="log")
  return fig
0.1s
Python

Positives

plot_data2(df,incremental=True,window=7)
1.5s
Python

Deaths

plot_data2(df2,incremental=True,window=7)
1.5s
Python
Runtimes (1)