dylanplummer commited on
Commit
25e57be
·
1 Parent(s): 5754989

update bar charts, much prettier

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -104,18 +104,39 @@ def full_report():
104
 
105
  country_df = df.groupby(['country', 'iso']).sum().reset_index()
106
  country_df = country_df.sort_values(by=['jumps'], ascending=False)
107
-
108
- country_avg = df.groupby(['country', 'iso']).mean().reset_index()
109
- country_avg = country_avg.sort_values(by=['jumps'], ascending=False)
110
-
111
- total = px.bar(country_df,
112
- x='country', y='jumps',
113
- title='Total Jumps by Country',
 
 
 
 
114
  template="plotly_dark")
115
- avg = px.bar(country_avg,
116
- x='country', y='jumps',
117
- title='Average Jumps per Daily Session',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  template="plotly_dark")
 
 
119
 
120
  country_df['rank'] = country_df['jumps'].rank(ascending=False)
121
  total_map = px.choropleth(country_df, locations="iso",
 
104
 
105
  country_df = df.groupby(['country', 'iso']).sum().reset_index()
106
  country_df = country_df.sort_values(by=['jumps'], ascending=False)
107
+ top_10_countries = country_df.iloc[:10]['country'].tolist()
108
+
109
+ country_df_to_plot = df.groupby(['country', 'iso', 'city']).sum().reset_index()
110
+ country_df_to_plot = country_df_to_plot[country_df_to_plot['country'].isin(top_10_countries)].reset_index(drop=True)
111
+ country_df_to_plot = country_df_to_plot.sort_values(by=['day', 'jumps'], ascending=True)
112
+ total = px.bar(country_df_to_plot,
113
+ y='country', x='jumps',
114
+ color='city',
115
+ title='Total Jumps by Country/City',
116
+ orientation='h',
117
+ category_orders={'country': top_10_countries},
118
  template="plotly_dark")
119
+ total.update_layout(showlegend=False)
120
+
121
+ city_df = df.groupby(['city', 'iso']).sum().reset_index()
122
+ city_df = city_df.sort_values(by=['jumps'], ascending=False)
123
+ city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
124
+ top_10_cities = city_df.iloc[:10]['city'].tolist()
125
+
126
+ city_df = df.groupby(['city', 'iso', 'day']).sum().reset_index()
127
+ city_df = city_df[city_df['city'] != '(not set)']
128
+ city_df['city'] = city_df.apply(lambda row: row['city'] + ', ' + row['iso'], axis=1)
129
+ city_df = city_df[city_df['city'].isin(top_10_cities)].reset_index(drop=True)
130
+ city_df = city_df.sort_values(by=['jumps'], ascending=True)
131
+
132
+ avg = px.bar(city_df,
133
+ y='city', x='jumps', color='day',
134
+ title='Total Jumps by City/Day',
135
+ orientation='h',
136
+ category_orders={'city': top_10_cities},
137
  template="plotly_dark")
138
+
139
+ avg.update_layout(showlegend=False)
140
 
141
  country_df['rank'] = country_df['jumps'].rank(ascending=False)
142
  total_map = px.choropleth(country_df, locations="iso",