File size: 1,942 Bytes
efd5e46
50e759f
94125f2
 
1439995
 
 
efd5e46
 
 
 
50e759f
 
0298713
d22be69
 
 
 
 
712f953
d1013d8
809762d
d22be69
463455f
 
 
 
 
 
4475a85
b01d9cd
426a82e
463455f
426a82e
463455f
 
61be3b7
 
 
 
426a82e
e9ec036
 
 
 
426a82e
 
d1013d8
426a82e
 
 
 
d1013d8
426a82e
 
 
 
 
 
 
 
 
 
e9ec036
 
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
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import re
from wordcloud import STOPWORDS

st.set_page_config(
    page_title="ESG for All",
    layout="wide",
    initial_sidebar_state="expanded")

df = pd.read_csv('all_filings_esg_text_180.csv')

with st.sidebar:
    st.title('ESG for All')
    
    year_list = list(df.Year.unique())[::-1]
    year_list = sorted(year_list)

    selected_year = st.selectbox('Select a year', year_list, index=len(year_list)-1).astype(str)

    cik_list = list(df.CIK.unique())[::-1]
    cik_list = sorted(cik_list)

    selected_cik = st.selectbox('Select a company', cik_list, index=len(cik_list)-1)
    df_selected_cik = df[df.CIK == selected_cik]

    st.link_button("Chat about ESG!", "https://fceaf6bb978ab08499.gradio.live")

col1, col2 = st.columns(2)

with col1:
    st.markdown('#### ESG Scores')
    
    df_selected_cik['Year'] = df_selected_cik['Year'].astype('string')
    df_selected_cik.sort_values('Year', inplace=True)
    df_selected_cik.set_index('Year', inplace=True)

    sns.lineplot(data=df_selected_cik[['e_score', 's_score', 'g_score']] )
    plt.xlabel('year')
    plt.ylabel('score')
    plt.legend(title='Legend', loc='upper left')
    st.pyplot(plt)

with col2:
    st.markdown('#### ESG Word Clouds')
    
    wc_list = ['E_Text', 'S_Text', 'G_Text']

    for x in wc_list:
        row = df_selected_cik.loc[selected_year]
        text = row.loc[x]
        text = re.sub(r'[^A-Za-z\s]', '', text)    
        text = text.lower()
        stopwords = set(STOPWORDS)
        text = ' '.join(word for word in text.split() if word not in stopwords)
        
        wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
        
        plt.figure(figsize=(10, 5))
        plt.imshow(wordcloud, interpolation='bilinear')
        plt.axis('off')
        st.pyplot(plt)