File size: 2,593 Bytes
a94f73c
 
 
 
 
1b7b20e
52e5c1d
a94f73c
 
c1cb7a7
a94f73c
 
 
11c744f
a94f73c
 
 
 
 
 
 
 
52e5c1d
 
 
 
 
 
 
 
a94f73c
52e5c1d
9c5ca90
0fc17ff
70c976f
52e5c1d
9c5ca90
52e5c1d
70c976f
9c5ca90
 
 
70c976f
9c5ca90
836753b
a94f73c
 
 
 
 
1b7b20e
f5502e6
 
52e5c1d
f5502e6
1b7b20e
a94f73c
 
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
# statistiques.py
import streamlit as st
import pandas as pd
import plotly.express as px
from data_manager import get_data
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt

def display_companies_by_sector(df):
    sector_counts = df['libelle_section_naf'].value_counts().reset_index()
    sector_counts.columns = ['Secteur', 'Nombre']
    fig = px.bar(sector_counts, x='Secteur', y='Nombre', title="Répartition des entreprises par secteur d'activité",
                 color='Nombre', labels={'Nombre':'Nombre d\'entreprises'}, template='plotly_white')
    fig.update_layout(xaxis_tickangle=-45)
    st.plotly_chart(fig)

def display_company_sizes(df):
    fig = px.histogram(df, x='tranche_effectif_entreprise', title="Distribution des tailles d'entreprises",
                       labels={'tranche_effectif_entreprise':'Taille de l\'entreprise'}, template='plotly_white')
    fig.update_traces(marker_color='green')
    st.plotly_chart(fig)

def display_companies_by_commune(df):
    commune_counts = df['commune'].value_counts(normalize=True).reset_index()
    commune_counts.columns = ['Commune', 'Pourcentage']
    fig = px.pie(commune_counts, values='Pourcentage', names='Commune', title='Pourcentage d\'entreprises par Commune',
                 template='plotly_white', hole=.3)
    fig.update_traces(textinfo='percent+label')
    st.plotly_chart(fig)

def display_rse_actions_wordcloud(df):
    st.header("Nuage de mots Actions RSE")
    
    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"])
    stopwords = STOPWORDS.union(custom_stopwords)
    
    text = " ".join(action for action in df['action_rse'].dropna())
    
    wordcloud = WordCloud(stopwords=stopwords, background_color="white", width=800, height=400).generate(text)
    
    fig, ax = plt.subplots()
    ax.imshow(wordcloud, interpolation='bilinear')
    ax.axis('off')
    st.pyplot(fig)

def main():
    st.title("Statistiques sur les entreprises engagées RSE")
    data, _ = get_data()
    df = pd.DataFrame(data)
    
    if not df.empty:
        display_companies_by_sector(df)
        display_company_sizes(df)
        display_companies_by_commune(df)
        display_rse_actions_wordcloud(df)

if __name__ == "__main__":
    main()