-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
160 lines (113 loc) · 5.13 KB
/
streamlit_app.py
File metadata and controls
160 lines (113 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
from plotly.offline import plot
st.set_page_config(layout="wide",
page_title="Recherche REG de Genève",
page_icon="🇨🇭",
)
types = {'TEL_PRINCIPAL': object}
df = pd.read_csv('Sources/reg.csv', index_col=0, dtype=types)
st.header('Entreprises du canton de Genève')
st.subheader('Filtres :')
fil1, fil2 = st.columns(2)
with fil1:
##### Filtre sur la taille d'entreprise.
size = ['Indépendant', '1-2 travailleurs', '3-5 travailleurs', '6-9 travailleurs', '10-19 travailleurs', '20-49 travailleurs', '50-99 travailleurs', '100-199 travailleurs', '200-499 travailleurs', '500-999 travailleurs', '1000-1999 travailleurs', 'Plus de 2000 travailleurs']
def filterSize(start, end, dataframe):
newSize = size[size.index(start):size.index(end)+1]
return dataframe[dataframe['TAILLE'].isin(newSize)]
start_size, end_size = st.select_slider(
label="Taille d'entreprise",
options= size,
value=('10-19 travailleurs', 'Plus de 2000 travailleurs'))
##### Filtre sur la commune de l'entreprise.
local = np.sort(df['PHYS_COMMUNE'].dropna().unique())
def filterCommune(filterList, dataframe):
return dataframe if not filterList else dataframe[dataframe['PHYS_COMMUNE'].isin(filterList)]
local_select = st.multiselect(
label="Communes",
options=local,
default=[],
placeholder="Par défault, toutes les communes sont prises en compte.")
with fil2:
##### Filtre sur l'année de création de l'entreprise.
year = np.sort(df['IMMAT_YEAR'].dropna().unique())
def fitreAnnee(minMax, dataframe):
return dataframe[(dataframe['IMMAT_YEAR'] >= minMax[0]) & (dataframe['IMMAT_YEAR'] <= minMax[1])]
year_range = st.slider(
label="Année d'immatriculation",
min_value= year[0],
max_value= year[-1],
value=(1980, year[-1]),
)
##### Filtre sur la definition Noga de l'entreprise.
noga = df.sort_values(by='CODE_NOGA')['DEFINITION_NOGA'].dropna().unique()
def filterNoga(filterList, dataframe):
return dataframe if not filterList else dataframe[dataframe['DEFINITION_NOGA'].isin(filterList)]
noga_select = st.multiselect(
label="Activités économiques",
options=noga,
default=[],
placeholder="Par défault, toutes les sections sont prises en compte.")
if noga_select != []:
branche = np.sort(df[df['DEFINITION_NOGA'].isin(noga_select)]['BRANCHE'].dropna().unique())
def filterBranche(filterList, dataframe):
return dataframe if not filterList else dataframe[dataframe['BRANCHE'].isin(filterList)]
branche_select = st.multiselect(
label="Branches d'activités économiques",
options=branche,
default=[],
placeholder="Par défault, toutes les branches sont prises en compte.")
st.subheader('Résultats :')
#####
custom_data = ["TEL_PRINCIPAL", "EMAIL", "SITE_INTERNET", "EMPLACEMENT"]
def myDataframe(df):
new = filterSize(start_size, end_size, df)
new = fitreAnnee(year_range, new)
new = filterCommune(local_select, new)
new = filterNoga(noga_select, new)
try:
new = filterBranche(branche_select, new)
except:
pass
new[custom_data] = new[custom_data].fillna('')
return new
update = myDataframe(df)
#####
col1, col2 = st.columns(2)
tableau = update[['NOM', 'TEL_PRINCIPAL', 'EMAIL', 'SITE_INTERNET', 'EMPLACEMENT', 'TYPE_LOCAL', 'BRANCHE', 'TAILLE',]]
with col1:
st.dataframe(tableau,
hide_index=True,
column_config={
"name": "NOM",
"SITE_INTERNET": st.column_config.LinkColumn("SITE_INTERNET")})
st.write(f"{len(update)} entreprises sélectionnées sur un totale de {len(df)}.")
with col2:
# Création de la figure
fig = px.scatter_mapbox(update, lat="latitude", lon="longitude", hover_name="NOM",
custom_data=custom_data,
center=dict(lat=46.2043, lon=6.1431), zoom=11, mapbox_style="carto-positron")
# Personnalisation de l'info-bulle
fig.update_traces(hovertemplate="<br>".join([
"<b>%{hovertext}</b>",
"Téléphone: %{customdata[0]} ",
"Email: %{customdata[1]}",
"Site Web: %{customdata[2]}",
"Adresse: %{customdata[3]}"
]))
# Mise en forme de la disposition
fig.update_layout(
margin={"r": 0, "t": 0, "l": 0, "b": 0}
)
# Affichage de la figure
st.plotly_chart(fig, use_container_width=True)
st.markdown('''
#### À propos :
* [Répertoire des entreprises du canton de Genève (REG)](https://ge.ch/sitg/fiche/2099)
* [Nomenclature générale des activités économiques (NOGA)](https://www.bfs.admin.ch/bfs/fr/home/statistiques/industrie-services/nomenclatures/noga.assetdetail.344103.html)
* [NAVREF](https://www.swisstopo.admin.ch/fr/conversion-coordonnees-navref)
* [Développeur](https://www.linkedin.com/in/gauthier-rammault/)
''')