import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
from io import StringIO
import requests
url_enhanced_sur_covid_19_eng = 'https://www.chp.gov.hk/files/misc/enhanced_sur_covid_19_eng.csv'
url_large_clusters_eng = 'https://www.chp.gov.hk/files/misc/large_clusters_eng.csv'
r = requests.get(url_enhanced_sur_covid_19_eng)
df_covid = pd.read_csv(StringIO(r.text))
r = requests.get(url_large_clusters_eng)
df_cluster = pd.read_csv(StringIO(r.text))
#Cleaning data
# Remove all the capital, non capital confusion
df_covid["HK/Non-HK resident"] = df_covid["HK/Non-HK resident"].str.upper()
# Convert Date to datetime format
df_covid["Report date"] = pd.to_datetime(df_covid["Report date"], infer_datetime_format=True)
# Cannot convert due to Asymptomatic entity
# df["Date of onset"] = pd.to_datetime(df["Date of onset"], infer_datetime_format=True)
## Second file
df_cluster["Case no."] = df_cluster[["Involved case number"]].applymap(lambda x: int(x.split(",")[0]))
# df_cluster[["Involved case number count"]] = df_cluster[["Involved case number"]].applymap(lambda x: len(x.split(","))) Done
df_cluster2 = pd.merge(df_covid, df_cluster, left_on="Case no.", right_on="Case no.")[["Cluster", "Report date", "Number of cases","Case no."]]
df_column_draw_pie_chart(df_covid,'Gender', 'Gender of the infected').show()
df_column_draw_pie_chart(df_covid, 'HK/Non-HK resident', 'Origin of the infected').show()
df_covid
df_column_draw_pie_chart(df_covid, 'Classification*', 'Classification of the cases').show()
df_column_count_line_chart(df_covid, 'Report date', 'Infected People Daily')
df_column_count_line_chart(df_covid, 'Report date', 'Infected People Daily', 'cumsum')
from plotly.subplots import make_subplots
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# fig.add_trace(go_df_bubble_chart(df_cluster2,"Report date","Case no.","Number of cases","Cluster", lineName="Big Cluster"))
fig.add_trace(go_df_count_plot(df_covid,"Report date", lineName="Total Infected Case",mode="cumsum"))
fig.add_trace(go_df_count_plot(df_covid,"Report date", lineName="Daily Infected Case",mode="count"), secondary_y=True)
# Add figure title
fig.update_layout(
title_text="Summary of Hong Kong COVID19 Cases"
)
# Set x-axis title
fig.update_xaxes(title_text="Date")
# Set y-axes titles
fig.update_yaxes(title_text="<b>Total</b> Cases", secondary_y=False)
fig.update_yaxes(title_text="<b>Daily</b> Cases", secondary_y=True)
fig.show()
from plotly.subplots import make_subplots
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
fig.add_trace(go_df_bubble_chart(df_cluster2,"Report date","Case no.","Number of cases","Cluster", lineName="Big Cluster"))
fig.add_trace(go_df_count_plot(df_covid,"Report date", lineName="Total Infected Case",mode="cumsum"))
fig.add_trace(go_df_count_plot(df_covid,"Report date", lineName="Daily Infected Case",mode="count"), secondary_y=True)
# Add figure title
fig.update_layout(
title_text="Summary of Hong Kong COVID19 Cases"
)
# Set x-axis title
fig.update_xaxes(title_text="Date")
# Set y-axes titles
fig.update_yaxes(title_text="<b>Total</b> Cases", secondary_y=False)
fig.update_yaxes(title_text="<b>Daily</b> Cases", secondary_y=True)
fig.show()