Skip to content

Instantly share code, notes, and snippets.

@databyjp
Last active February 26, 2020 06:06
Show Gist options
  • Save databyjp/6af79f84190f3eac74636c5a2ddc3e43 to your computer and use it in GitHub Desktop.
Save databyjp/6af79f84190f3eac74636c5a2ddc3e43 to your computer and use it in GitHub Desktop.
# TREEMAPS
travel_cats = ['home', 'travelled', 'rest_cats']
travel_grp_df = box_df.groupby(travel_cats).sum()
travel_grp_df = travel_grp_df.assign(games=box_df.groupby(travel_cats)['minutes_played'].count())
travel_grp_df.reset_index(drop=False, inplace=True)
chart_cats = ['home_str', 'travelled_str', 'rest_cats']
home_away = pd.Series(['Home ' * i for i in travel_grp_df.home.values]) + pd.Series(['Away ' * (1-i) for i in travel_grp_df.home.values])
travel_grp_df['home_str'] = home_away
travelled = pd.Series(['Travelled ' * i for i in travel_grp_df.travelled.values]) + pd.Series(['Stayed ' * (1-i) for i in travel_grp_df.travelled.values])
travel_grp_df['travelled_str'] = travelled
travel_grp_df['rest_cats'] = travel_grp_df['rest_cats'] + "'<BR>Rest"
travel_grp_df['WIN%'] = travel_grp_df.win/travel_grp_df.games * 100
fig = px.treemap(
travel_grp_df, path=['home_str', 'travelled_str', 'rest_cats'], values='games', color='WIN%', color_continuous_midpoint=50, color_continuous_scale=px.colors.diverging.Portland)
fig.show()
fig = px.treemap(
travel_grp_df, path=['home_str', 'rest_cats', 'travelled_str'], values='games', color='WIN%', color_continuous_midpoint=50, color_continuous_scale=px.colors.diverging.Portland)
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment