prototype / app.py
sneves's picture
Update app.py
4475a85 verified
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)