Last active
July 25, 2020 19:23
-
-
Save BindiChen/de39182e050962c0b627d5146e3bce09 to your computer and use it in GitHub Desktop.
Interactive Data Visualization for exploring Coronavirus Spreads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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