Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.