Spaces:
Runtime error
Runtime error
Commit
·
1b7b20e
1
Parent(s):
f5502e6
V2-Liste_MAP_Stat_16
Browse files- statistiques.py +3 -15
statistiques.py
CHANGED
|
@@ -4,20 +4,17 @@ import pandas as pd
|
|
| 4 |
import plotly.express as px
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
from data_manager import get_data
|
| 7 |
-
from wordcloud import WordCloud,STOPWORDS
|
| 8 |
|
| 9 |
def display_companies_by_sector(df):
|
| 10 |
-
# Assurez-vous d'utiliser le nom correct de la colonne ici
|
| 11 |
sector_counts = df['libelle_section_naf'].value_counts().reset_index()
|
| 12 |
sector_counts.columns = ['Secteur', 'Nombre']
|
| 13 |
fig = px.bar(sector_counts, x='Secteur', y='Nombre', title="Répartition des entreprises par secteur d'activité",
|
| 14 |
color='Nombre', labels={'Nombre':'Nombre d\'entreprises'}, template='plotly_white')
|
| 15 |
-
# Rotation des étiquettes de l'axe des x pour une meilleure lisibilité
|
| 16 |
fig.update_layout(xaxis_tickangle=-45)
|
| 17 |
st.plotly_chart(fig)
|
| 18 |
|
| 19 |
def display_company_sizes(df):
|
| 20 |
-
# Remplacez 'tranche_effectif_entreprise' par le nom correct de la colonne
|
| 21 |
fig = px.histogram(df, x='tranche_effectif_entreprise', title="Distribution des tailles d'entreprises",
|
| 22 |
labels={'tranche_effectif_entreprise':'Taille de l\'entreprise'}, template='plotly_white')
|
| 23 |
fig.update_traces(marker_color='green')
|
|
@@ -26,34 +23,25 @@ def display_company_sizes(df):
|
|
| 26 |
def display_rse_actions_wordcloud(df):
|
| 27 |
st.title("Cartographie des Actions RSE")
|
| 28 |
|
| 29 |
-
# Définir les mots à exclure
|
| 30 |
custom_stopwords = set(["d ", "des", "qui", "ainsi", "toute", "hors", "plus", "cette", "afin", "via", "d'", "sa", "dans", "ont", "avec", "aux", "ce", "chez", "ont", "cela", "la", "un", "avons", "par", "c'est", "s'est", "aussi", "leurs", "d'un", "nos", "les", "sur", "ses", "tous", "nous", "du", "notre", "de", "et", "est", "pour", "le", "une", "se", "en", "au", "à", "que", "sont", "leur", "son"])
|
| 31 |
-
|
| 32 |
-
# Ajouter vos mots à exclure aux stop words par défaut de wordcloud
|
| 33 |
stopwords = STOPWORDS.union(custom_stopwords)
|
| 34 |
-
|
| 35 |
-
# Préparation des données
|
| 36 |
text = " ".join(action for action in df['action_rse'].dropna())
|
| 37 |
-
|
| 38 |
-
# Génération du nuage de mots avec les stop words personnalisés
|
| 39 |
wordcloud = WordCloud(stopwords=stopwords, background_color="white", width=800, height=400).generate(text)
|
| 40 |
|
| 41 |
-
# Affichage du nuage de mots
|
| 42 |
fig, ax = plt.subplots()
|
| 43 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 44 |
ax.axis('off')
|
| 45 |
st.pyplot(fig)
|
| 46 |
|
| 47 |
-
|
| 48 |
def main():
|
| 49 |
st.title("Statistiques sur les entreprises engagées RSE")
|
| 50 |
data, _ = get_data()
|
| 51 |
df = pd.DataFrame(data)
|
| 52 |
|
| 53 |
-
|
| 54 |
display_companies_by_sector(df)
|
| 55 |
display_company_sizes(df)
|
| 56 |
display_rse_actions_wordcloud(df)
|
| 57 |
-
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|
|
|
|
| 4 |
import plotly.express as px
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
from data_manager import get_data
|
| 7 |
+
from wordcloud import WordCloud, STOPWORDS
|
| 8 |
|
| 9 |
def display_companies_by_sector(df):
|
|
|
|
| 10 |
sector_counts = df['libelle_section_naf'].value_counts().reset_index()
|
| 11 |
sector_counts.columns = ['Secteur', 'Nombre']
|
| 12 |
fig = px.bar(sector_counts, x='Secteur', y='Nombre', title="Répartition des entreprises par secteur d'activité",
|
| 13 |
color='Nombre', labels={'Nombre':'Nombre d\'entreprises'}, template='plotly_white')
|
|
|
|
| 14 |
fig.update_layout(xaxis_tickangle=-45)
|
| 15 |
st.plotly_chart(fig)
|
| 16 |
|
| 17 |
def display_company_sizes(df):
|
|
|
|
| 18 |
fig = px.histogram(df, x='tranche_effectif_entreprise', title="Distribution des tailles d'entreprises",
|
| 19 |
labels={'tranche_effectif_entreprise':'Taille de l\'entreprise'}, template='plotly_white')
|
| 20 |
fig.update_traces(marker_color='green')
|
|
|
|
| 23 |
def display_rse_actions_wordcloud(df):
|
| 24 |
st.title("Cartographie des Actions RSE")
|
| 25 |
|
|
|
|
| 26 |
custom_stopwords = set(["d ", "des", "qui", "ainsi", "toute", "hors", "plus", "cette", "afin", "via", "d'", "sa", "dans", "ont", "avec", "aux", "ce", "chez", "ont", "cela", "la", "un", "avons", "par", "c'est", "s'est", "aussi", "leurs", "d'un", "nos", "les", "sur", "ses", "tous", "nous", "du", "notre", "de", "et", "est", "pour", "le", "une", "se", "en", "au", "à", "que", "sont", "leur", "son"])
|
|
|
|
|
|
|
| 27 |
stopwords = STOPWORDS.union(custom_stopwords)
|
|
|
|
|
|
|
| 28 |
text = " ".join(action for action in df['action_rse'].dropna())
|
|
|
|
|
|
|
| 29 |
wordcloud = WordCloud(stopwords=stopwords, background_color="white", width=800, height=400).generate(text)
|
| 30 |
|
|
|
|
| 31 |
fig, ax = plt.subplots()
|
| 32 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 33 |
ax.axis('off')
|
| 34 |
st.pyplot(fig)
|
| 35 |
|
|
|
|
| 36 |
def main():
|
| 37 |
st.title("Statistiques sur les entreprises engagées RSE")
|
| 38 |
data, _ = get_data()
|
| 39 |
df = pd.DataFrame(data)
|
| 40 |
|
| 41 |
+
if not df.empty:
|
| 42 |
display_companies_by_sector(df)
|
| 43 |
display_company_sizes(df)
|
| 44 |
display_rse_actions_wordcloud(df)
|
| 45 |
+
|
| 46 |
if __name__ == "__main__":
|
| 47 |
main()
|