File size: 2,780 Bytes
7c987c3
a94f73c
 
 
 
1b7b20e
52e5c1d
a94f73c
 
c1cb7a7
a94f73c
900731b
1aaa626
a4e86cd
1aaa626
a94f73c
 
 
900731b
ebc12f5
a94f73c
a4e86cd
a94f73c
 
52e5c1d
 
 
900731b
52e5c1d
 
 
 
a94f73c
52e5c1d
9c5ca90
a4e86cd
70c976f
52e5c1d
9c5ca90
52e5c1d
70c976f
9c5ca90
 
 
70c976f
9c5ca90
836753b
a94f73c
 
 
 
1b7b20e
7c987c3
 
 
f5254fa
f5502e6
f5254fa
f5502e6
f5254fa
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
60
61
62
63
64
65
66

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',
                 color='Nombre', labels={'Nombre': ''}, template='plotly_white')
    fig.update_layout(xaxis_tickangle=-45, showlegend=False)
    fig.update_traces(showlegend=False)
    st.plotly_chart(fig)

def display_company_sizes(df):
    fig = px.histogram(df, x='tranche_effectif_entreprise',
                       labels={'tranche_effectif_entreprise':"Taille de l'entreprise", 'count':'Nombre'}, template='plotly_white')
    fig.update_traces(marker_color='green')
    fig.update_layout(yaxis_title="Nombre")
    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',
                 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(["l", "d", "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():
    data, _ = get_data()
    df = pd.DataFrame(data)
    
    if not df.empty:
        st.markdown("## OPEN DATA RSE")
        st.markdown("### Statistiques sur les entreprises engagées RSE")
        
        st.header("Répartition des entreprises par secteur d'activité")
        display_companies_by_sector(df)
        st.header("Distribution des tailles d'entreprises")
        display_company_sizes(df)
        st.header("Pourcentage d'entreprises par Commune")
        display_companies_by_commune(df)
        display_rse_actions_wordcloud(df)

if __name__ == "__main__":
    main()