CoolFace
Apppublic

LaurentTRIPIED/OpenData-Projet-RSE

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
statistiques.py66 linesDownload Raw Back to root
1 2import streamlit as st3import pandas as pd4import plotly.express as px5from data_manager import get_data6from wordcloud import WordCloud, STOPWORDS7import matplotlib.pyplot as plt8 9def 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',13                 color='Nombre', labels={'Nombre': ''}, template='plotly_white')14    fig.update_layout(xaxis_tickangle=-45, showlegend=False)15    fig.update_traces(showlegend=False)16    st.plotly_chart(fig)17 18def display_company_sizes(df):19    fig = px.histogram(df, x='tranche_effectif_entreprise',20                       labels={'tranche_effectif_entreprise':"Taille de l'entreprise", 'count':'Nombre'}, template='plotly_white')21    fig.update_traces(marker_color='green')22    fig.update_layout(yaxis_title="Nombre")23    st.plotly_chart(fig)24 25def display_companies_by_commune(df):26    commune_counts = df['commune'].value_counts(normalize=True).reset_index()27    commune_counts.columns = ['Commune', 'Pourcentage']28    fig = px.pie(commune_counts, values='Pourcentage', names='Commune',29                 template='plotly_white', hole=.3)30    fig.update_traces(textinfo='percent+label')31    st.plotly_chart(fig)32 33def display_rse_actions_wordcloud(df):34    st.header("Nuage de mots Actions RSE")35    36    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"])37    stopwords = STOPWORDS.union(custom_stopwords)38    39    text = " ".join(action for action in df['action_rse'].dropna())40    41    wordcloud = WordCloud(stopwords=stopwords, background_color="white", width=800, height=400).generate(text)42    43    fig, ax = plt.subplots()44    ax.imshow(wordcloud, interpolation='bilinear')45    ax.axis('off')46    st.pyplot(fig)47 48def main():49    data, _ = get_data()50    df = pd.DataFrame(data)51    52    if not df.empty:53        st.markdown("## OPEN DATA RSE")54        st.markdown("### Statistiques sur les entreprises engagées RSE")55        56        st.header("Répartition des entreprises par secteur d'activité")57        display_companies_by_sector(df)58        st.header("Distribution des tailles d'entreprises")59        display_company_sizes(df)60        st.header("Pourcentage d'entreprises par Commune")61        display_companies_by_commune(df)62        display_rse_actions_wordcloud(df)63 64if __name__ == "__main__":65    main()66