analist commited on
Commit
16ea8f5
·
verified ·
1 Parent(s): 6357913

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -43
app.py CHANGED
@@ -25,6 +25,7 @@ import plotly.express as px
25
  import streamlit as st
26
 
27
  st.set_page_config(layout="wide")
 
28
 
29
  # Données de test: Il y a 4 foyers par quartier et 10 quartiers répartis dans 2 communes pour faire les test.
30
  #
@@ -130,32 +131,32 @@ DATA = [
130
 
131
 
132
  data = pd.DataFrame(DATA)
133
- data.head()
134
 
135
 
136
  # In[5]:
137
 
138
 
139
  data['score'] = (data['score_sanitaire'] + data['score_foyer']) / 2
140
- data.head(2)
141
 
142
 
143
  # In[6]:
144
 
145
 
146
- data['score responsabilité'] = data['score_sanitaire'] - data['score_foyer']
147
 
148
 
149
  # In[7]:
150
 
151
 
152
- data.head()
153
 
154
 
155
  # In[8]:
156
 
157
 
158
- np.average(data['score'], axis=0, weights=data.index)
159
 
160
 
161
  # In[9]:
@@ -169,7 +170,7 @@ def moyenne_par_quartier(quartiers, id, scoring="score"):
169
  # In[10]:
170
 
171
 
172
- moyenne_par_quartier(data, 2)
173
 
174
 
175
  # Moyenne pondérée pour les quartiers qui ont peu de foyers enrégistrés dans une communauté.
@@ -186,7 +187,7 @@ def moyenne_par_communaute(data, community_id, scoring="score"):
186
  # In[12]:
187
 
188
 
189
- moyenne_par_communaute(data, 4)
190
 
191
 
192
  # In[13]:
@@ -281,7 +282,7 @@ for row in gdf.iterrows():
281
  # In[22]:
282
 
283
 
284
- id_regions
285
 
286
 
287
  # In[23]:
@@ -289,7 +290,7 @@ id_regions
289
 
290
  data['quartier_name'] = data['quartier_id'].apply(lambda x: id_quartier[x])
291
  data['community_name'] = data['community_id'].apply(lambda x: id_regions[x])
292
- data.head()
293
 
294
 
295
  # In[ ]:
@@ -342,13 +343,13 @@ new_df = pd.DataFrame(data={
342
  'scores': scores,
343
  "quartier_id": ids
344
  })
345
- new_df.head()
346
 
347
 
348
  # In[31]:
349
 
350
 
351
- new_df.to_csv('new_df.csv', index=False)
352
 
353
 
354
  # In[39]:
@@ -367,7 +368,7 @@ gdf_merged_q = pd.merge(new_gdf_q, new_df, how='left', left_on="adm2nm", right_o
367
  # In[60]:
368
 
369
 
370
- gdf_merged_q.head()
371
 
372
 
373
  # In[61]:
@@ -394,22 +395,24 @@ gdf_merged_q[gdf_merged_q['adm2nm'] == "Blitta"]
394
 
395
  # In[86]:
396
 
397
-
398
- fig = px.choropleth_mapbox(gdf_merged_q,
399
- geojson=geojson,
400
- locations=gdf_merged_q.index,
401
- color='scores',
402
- mapbox_style="carto-positron",
403
- title="Scores de Propreté Pour Les Préfectures Du Togo",
404
- hover_name="adm2nm",
405
- color_continuous_scale="Viridis"
406
- )
407
- fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
408
- st.plotly_chart(fig)
 
 
409
  # In[101]:
410
 
411
 
412
- gdf_merged_q.to_csv('merged_q.csv', index=False)
413
 
414
 
415
  # In[ ]:
@@ -423,7 +426,7 @@ gdf_merged_q.to_csv('merged_q.csv', index=False)
423
  # In[78]:
424
 
425
 
426
- id_regions
427
 
428
 
429
  # In[79]:
@@ -441,7 +444,7 @@ for q in regions_id:
441
  print(q)
442
  rm[q] = moyenne_par_communaute(data, q)
443
 
444
- rm
445
 
446
 
447
  # In[81]:
@@ -460,7 +463,6 @@ region_df = pd.DataFrame({
460
  'scores': scores
461
  })
462
 
463
- region_df.head()
464
 
465
 
466
  # In[ ]:
@@ -495,15 +497,12 @@ respon_df = pd.DataFrame(data={
495
  'scores': scores,
496
  "quartier_id": ids
497
  })
498
- respon_df.head()
499
 
500
 
501
  # In[102]:
502
 
503
 
504
  gdf_merged_q_r = pd.merge(new_gdf_q, respon_df, left_on="adm2nm", right_on="quartier", how='left')
505
- gdf_merged_q_r.to_csv('merged_q_r.csv', index=False)
506
- gdf_merged_q_r.head()
507
 
508
 
509
  # In[ ]:
@@ -514,18 +513,20 @@ gdf_merged_q_r.head()
514
 
515
  # In[100]:
516
 
517
-
518
- fig = px.choropleth_mapbox(gdf_merged_q_r,
519
- geojson=geojson,
520
- locations=gdf_merged_q.index,
521
- color='scores',
522
- mapbox_style="carto-positron",
523
- title="Scores de Propreté Pour Les Préfectures Du Togo",
524
- hover_name="adm2nm",
525
- color_continuous_scale="Viridis"
526
- )
527
- fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
528
- st.plotly_chart(fig)
 
 
529
 
530
 
531
  # In[ ]:
 
25
  import streamlit as st
26
 
27
  st.set_page_config(layout="wide")
28
+ col1, col2 = st.columns(2)
29
 
30
  # Données de test: Il y a 4 foyers par quartier et 10 quartiers répartis dans 2 communes pour faire les test.
31
  #
 
131
 
132
 
133
  data = pd.DataFrame(DATA)
134
+ #data.head()
135
 
136
 
137
  # In[5]:
138
 
139
 
140
  data['score'] = (data['score_sanitaire'] + data['score_foyer']) / 2
141
+ #data.head(2)
142
 
143
 
144
  # In[6]:
145
 
146
 
147
+ #data['score responsabilité'] = data['score_sanitaire'] - data['score_foyer']
148
 
149
 
150
  # In[7]:
151
 
152
 
153
+ #data.head()
154
 
155
 
156
  # In[8]:
157
 
158
 
159
+ #np.average(data['score'], axis=0, weights=data.index)
160
 
161
 
162
  # In[9]:
 
170
  # In[10]:
171
 
172
 
173
+ #moyenne_par_quartier(data, 2)
174
 
175
 
176
  # Moyenne pondérée pour les quartiers qui ont peu de foyers enrégistrés dans une communauté.
 
187
  # In[12]:
188
 
189
 
190
+ #moyenne_par_communaute(data, 4)
191
 
192
 
193
  # In[13]:
 
282
  # In[22]:
283
 
284
 
285
+ #id_regions
286
 
287
 
288
  # In[23]:
 
290
 
291
  data['quartier_name'] = data['quartier_id'].apply(lambda x: id_quartier[x])
292
  data['community_name'] = data['community_id'].apply(lambda x: id_regions[x])
293
+ #data.head()
294
 
295
 
296
  # In[ ]:
 
343
  'scores': scores,
344
  "quartier_id": ids
345
  })
346
+ #new_df.head()
347
 
348
 
349
  # In[31]:
350
 
351
 
352
+ #new_df.to_csv('new_df.csv', index=False)
353
 
354
 
355
  # In[39]:
 
368
  # In[60]:
369
 
370
 
371
+ #gdf_merged_q.head()
372
 
373
 
374
  # In[61]:
 
395
 
396
  # In[86]:
397
 
398
+ with col1:
399
+ st.header('Score Propre')
400
+
401
+ fig = px.choropleth_mapbox(gdf_merged_q,
402
+ geojson=geojson,
403
+ locations=gdf_merged_q.index,
404
+ color='scores',
405
+ mapbox_style="carto-positron",
406
+ title="Scores de Propreté Pour Les Préfectures Du Togo",
407
+ hover_name="adm2nm",
408
+ color_continuous_scale="Viridis"
409
+ )
410
+ fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
411
+ st.plotly_chart(fig)
412
  # In[101]:
413
 
414
 
415
+ #gdf_merged_q.to_csv('merged_q.csv', index=False)
416
 
417
 
418
  # In[ ]:
 
426
  # In[78]:
427
 
428
 
429
+ #id_regions
430
 
431
 
432
  # In[79]:
 
444
  print(q)
445
  rm[q] = moyenne_par_communaute(data, q)
446
 
447
+ #rm
448
 
449
 
450
  # In[81]:
 
463
  'scores': scores
464
  })
465
 
 
466
 
467
 
468
  # In[ ]:
 
497
  'scores': scores,
498
  "quartier_id": ids
499
  })
 
500
 
501
 
502
  # In[102]:
503
 
504
 
505
  gdf_merged_q_r = pd.merge(new_gdf_q, respon_df, left_on="adm2nm", right_on="quartier", how='left')
 
 
506
 
507
 
508
  # In[ ]:
 
513
 
514
  # In[100]:
515
 
516
+ with col2:
517
+
518
+ st.header('Scores Responsable')
519
+ fig = px.choropleth_mapbox(gdf_merged_q_r,
520
+ geojson=geojson,
521
+ locations=gdf_merged_q.index,
522
+ color='scores',
523
+ mapbox_style="carto-positron",
524
+ title="Scores de Propreté Pour Les Préfectures Du Togo",
525
+ hover_name="adm2nm",
526
+ color_continuous_scale="Viridis"
527
+ )
528
+ fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0})
529
+ st.plotly_chart(fig)
530
 
531
 
532
  # In[ ]: