Spaces:
Sleeping
Sleeping
File size: 1,032 Bytes
6f00d18 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import json
@st.cache_data
def load_covid_data(fp):
print('Running load_covid_data...')
# read in the csv via the link
df = pd.read_csv(fp)
# Creating the National Average
national_average = df.groupby('date')['cases_avg_per_100k'].mean()
# turn that into a data frame
national_average = pd.DataFrame(national_average).reset_index()
# create a state column
national_average['state'] = 'National Average'
# add it to the main dataframe
df = pd.concat([df, national_average])
df['datetime'] = pd.to_datetime(df['date'])
return(df)
# loading the data
fp = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/rolling-averages/us-states.csv'
df = load_covid_data(fp)
summary_stats = df.groupby('state')['cases_avg_per_100k'].agg(['mean', 'median', 'min', 'max', 'std'])
st.dataframe(
summary_stats.style.highlight_max(axis=0, color='red'),
use_container_width=True)
|