Create esg_statistics.py
Browse files- esg_statistics.py +45 -0
esg_statistics.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly.graph_objects as go
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def compute_esg_keyword_distribution(text):
|
| 5 |
+
text = text.lower()
|
| 6 |
+
|
| 7 |
+
environmental_keywords = ["emission", "carbon", "climate", "energy", "waste"]
|
| 8 |
+
social_keywords = ["diversity", "employee", "community", "health", "safety"]
|
| 9 |
+
governance_keywords = ["board", "compliance", "audit", "ethics", "policy"]
|
| 10 |
+
|
| 11 |
+
e_count = sum(text.count(word) for word in environmental_keywords)
|
| 12 |
+
s_count = sum(text.count(word) for word in social_keywords)
|
| 13 |
+
g_count = sum(text.count(word) for word in governance_keywords)
|
| 14 |
+
|
| 15 |
+
total = max(e_count + s_count + g_count, 1)
|
| 16 |
+
|
| 17 |
+
return {
|
| 18 |
+
"Environmental": e_count,
|
| 19 |
+
"Social": s_count,
|
| 20 |
+
"Governance": g_count,
|
| 21 |
+
"Total": total
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def generate_esg_statistics_chart(text):
|
| 26 |
+
stats = compute_esg_keyword_distribution(text)
|
| 27 |
+
|
| 28 |
+
fig = go.Figure(data=[
|
| 29 |
+
go.Pie(
|
| 30 |
+
labels=["Environmental", "Social", "Governance"],
|
| 31 |
+
values=[
|
| 32 |
+
stats["Environmental"],
|
| 33 |
+
stats["Social"],
|
| 34 |
+
stats["Governance"]
|
| 35 |
+
],
|
| 36 |
+
hole=0.5
|
| 37 |
+
)
|
| 38 |
+
])
|
| 39 |
+
|
| 40 |
+
fig.update_layout(
|
| 41 |
+
title="ESG Keyword Distribution (Donut Chart)",
|
| 42 |
+
template="plotly_dark"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
return fig
|