Skip to content

Instantly share code, notes, and snippets.

@BindiChen
Last active July 25, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BindiChen/de39182e050962c0b627d5146e3bce09 to your computer and use it in GitHub Desktop.
Save BindiChen/de39182e050962c0b627d5146e3bce09 to your computer and use it in GitHub Desktop.
Interactive Data Visualization for exploring Coronavirus Spreads
import pandas as pd
import altair as alt
# Load data
full_clean_data = pd.read_csv('covid_19_clean_complete.csv', parse_dates=['Date'])
# Select a list of countries
countries = ['US', 'Italy', 'China', 'Spain', 'France', 'Iran', 'United Kingdom', 'Switzerland']
selected_data = full_clean_data[full_clean_data['Country/Region'].isin(countries)]
interval = alt.selection_interval()
circle = alt.Chart(selected_data).mark_circle().encode(
x='monthdate(Date):O',
y='Country/Region',
color=alt.condition(interval, 'Country/Region', alt.value('lightgray')),
size=alt.Size('New cases:Q',
scale=alt.Scale(range=[0, 3000]),
legend=alt.Legend(title='Daily new cases')
)
).properties(
width=1000,
height=300,
selection=interval
)
bars = alt.Chart(selected_data).mark_bar().encode(
y='Country/Region',
color='Country/Region',
x='sum(New cases):Q'
).properties(
width=1000
).transform_filter(
interval
)
circle & bars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment