Skip to content

Instantly share code, notes, and snippets.

@barrysmyth
Last active May 26, 2020 08:41
Show Gist options
  • Save barrysmyth/863c014da53d561bcdf432406b7d5693 to your computer and use it in GitHub Desktop.
Save barrysmyth/863c014da53d561bcdf432406b7d5693 to your computer and use it in GitHub Desktop.
# Load in sample dataset
df = pd.read_csv('../data/segmented_bar_graph_example_data.csv').set_index('country').fillna(0)
# Extract the log(deaths)
# Use the sorted index from weeklies to sort deaths in the same way.
deaths = df.loc[weeklies.index]['log_deaths']
# Separate the weekly mobility drops and sort them in descending order of the sum of the
# the weekly drops
weeklies = df.drop(columns=['log_deaths'])\
.assign(s=df.sum(axis=1))\
.sort_values('s', ascending=False)\
.drop('s', axis=1)
weeklies.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment