Spaces:
Sleeping
Sleeping
danielrosehill
commited on
Commit
·
2aacdd5
1
Parent(s):
527d990
updated
Browse files- .vscode/settings.json +3 -0
- app.py +65 -0
- data-source.md +0 -0
- requirements.txt +5 -0
.vscode/settings.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${profileName}${separator}${appName}${separator}[Branch: main]"
|
3 |
+
}
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# App title and description
|
6 |
+
st.title("Monetize GHG Emissions Explorer")
|
7 |
+
st.write("This application was developed by Daniel Rosehill. Its purpose is to help the user to explore the relationship between companies profitability and their greenhouse gas emissions. Greenhouse gas emissions are monetized at the rate of 236 per ton of carbon dioxide equivalents as proposed in 2023 by the International Foundation for valuing impacts based upon an extensive consultation process informed by the latest scientific evidence.")
|
8 |
+
|
9 |
+
# Load data from GitHub URL
|
10 |
+
url = "https://raw.githubusercontent.com/danielrosehill/GHG-Emissions-Data-Pipeline/refs/heads/main/company_data.csv"
|
11 |
+
data = pd.read_csv(url)
|
12 |
+
|
13 |
+
# Process data
|
14 |
+
data['total_emissions'] = data['scope_1_emissions'] + data['scope_2_emissions'] + data['scope_3_emissions']
|
15 |
+
data['total_monetized_emissions'] = data['total_emissions'] * 236 / 1000 # in billions of USD
|
16 |
+
|
17 |
+
# Create sidebar for user input
|
18 |
+
st.sidebar.title("Filters")
|
19 |
+
sector_options = data['sector'].unique().tolist()
|
20 |
+
industry_selection = st.sidebar.multiselect("Select Industry", sector_options, default=sector_options)
|
21 |
+
|
22 |
+
# Filter data based on user selection
|
23 |
+
filtered_data = data[data['sector'].isin(industry_selection)]
|
24 |
+
|
25 |
+
# Allow user to select up to 5 individual companies
|
26 |
+
company_options = filtered_data['company_name'].unique().tolist()
|
27 |
+
company_selection = st.sidebar.multiselect("Select Companies (max 5)", company_options, default=company_options[:5])
|
28 |
+
if len(company_selection) > 5:
|
29 |
+
st.sidebar.warning("Please select up to 5 companies.")
|
30 |
+
|
31 |
+
# Further filter data based on company selection
|
32 |
+
final_data = filtered_data[filtered_data['company_name'].isin(company_selection)]
|
33 |
+
|
34 |
+
# Display data table
|
35 |
+
st.write("### Data Table")
|
36 |
+
st.dataframe(final_data[['company_name', 'ebitda_2022', 'total_monetized_emissions']])
|
37 |
+
|
38 |
+
# Plot bar chart
|
39 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
40 |
+
bar_width = 0.35
|
41 |
+
index = range(len(final_data))
|
42 |
+
|
43 |
+
# Plot profitability (positive values)
|
44 |
+
bars1 = ax.bar(index, final_data['ebitda_2022'], bar_width, label='Profitability', color='green')
|
45 |
+
|
46 |
+
# Plot monetized emissions (negative values)
|
47 |
+
bars2 = ax.bar([p + bar_width for p in index], -final_data['total_monetized_emissions'], bar_width, label='Monetized Emissions', color='red')
|
48 |
+
|
49 |
+
# Add labels and title
|
50 |
+
ax.set_xlabel('Company')
|
51 |
+
ax.set_ylabel('Values')
|
52 |
+
ax.set_title('Profitability vs Monetized Emissions')
|
53 |
+
ax.set_xticks([p + bar_width / 2 for p in index])
|
54 |
+
ax.set_xticklabels(final_data['company_name'], rotation=45, ha='right')
|
55 |
+
ax.legend()
|
56 |
+
|
57 |
+
# Display the plot
|
58 |
+
st.write("### Visualization")
|
59 |
+
st.pyplot(fig)
|
60 |
+
|
61 |
+
# Calculate and display correlation
|
62 |
+
correlation = final_data['ebitda_2022'].corr(final_data['total_monetized_emissions'])
|
63 |
+
st.write("### Correlation Calculation")
|
64 |
+
st.write(f"The correlation between profitability and monetized emissions is: {correlation:.2f}")
|
65 |
+
st.write("A negative correlation indicates that companies are less profitable if they emit more.")
|
data-source.md
ADDED
File without changes
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas==2.1.0
|
2 |
+
plotly==5.17.0
|
3 |
+
streamlit==1.27.0
|
4 |
+
numpy==1.24.3
|
5 |
+
matplotlib
|