Py.Cafe

Feanor1992/

Green Climate Fund

Dash Color Coder

DocsPricing
  • ODL-Export-Countries.csv
  • app.py
  • requirements.txt
app.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import pandas as pd
import plotly.express as px
from dash import Dash, dcc, html, Input, Output

df = pd.read_csv('https://py.cafe/files/Feanor1992/Green Climate Fund/ODL-Export-Countries.csv')

# Convert columns to numeric
df['RP Financing $'] = pd.to_numeric(df['RP Financing $'], errors='coerce')
df['FA Financing $'] = pd.to_numeric(df['FA Financing $'], errors='coerce')

# Handle missing values in the financing columns
df['RP Financing $'] = df['RP Financing $'].fillna(0)
df['FA Financing $'] = df['FA Financing $'].fillna(0)

# Create a new column for total financing
df['Total Financing $'] = df['RP Financing $'] + df['FA Financing $']
df['Total Financing $'] = pd.to_numeric(df['Total Financing $'])

# Analyze data by region
region_summary = df.groupby('Region').agg(
    total_financing=('Total Financing $', 'sum'),
    avg_financing=('Total Financing $', 'mean'),
    num_countries=('Country Name', 'count')
).reset_index()

region_summary['total_financing'] = pd.to_numeric(region_summary['total_financing'])
region_summary['avg_financing'] = pd.to_numeric(region_summary['avg_financing'])

# Analyze SIDS and LDCs
sids_ldcs_summary = df.groupby(['SIDS', 'LDCs']).agg(
    total_financing=('Total Financing $', 'sum'),
    avg_financing=('Total Financing $', 'mean'),
    num_countries=('Country Name', 'count')
).reset_index()

sids_ldcs_summary['total_financing'] = pd.to_numeric(sids_ldcs_summary['total_financing'])
sids_ldcs_summary['avg_financing'] = pd.to_numeric(sids_ldcs_summary['avg_financing'])

# Identify top countries by total financing
top_countries = df.nlargest(
    10,
    'Total Financing $'
)[['Country Name', 'Total Financing $']]

top_countries['Total Financing $'] = pd.to_numeric(top_countries['Total Financing $'])

# Analyze financing distribution
financing_distribution = df[['RP Financing $', 'FA Financing $']].describe().T
financing_distribution = financing_distribution.round(2)

# Create a Dash app
app = Dash(__name__)
app.title = "Green Climate Analysis"

# Choropleth Map
choropleth_map = px.choropleth(
    data_frame=df,
    locations='ISO3',
    color='Total Financing $',
    color_continuous_scale='Mint',
    hover_name='Country Name',
    hover_data={
        'Region': True,
        'SIDS': True,
        'LDCs': True,
        'RP Financing $': ':.2f',
        'FA Financing $': True,
        'Total Financing $': ':.2f'
    },
    title='Total Financing by Country',
    projection='orthographic'
)
choropleth_map.update_layout(
    template="plotly_dark",
    font=dict(color="white"),
    title_font_size=20,
    paper_bgcolor="rgba(0, 0, 0, 0)",
    geo_bgcolor="rgba(0, 0, 0, 0)"
)

# Financing Distribution
financing_distribution_chart = px.bar(
    df,
    x='Country Name',
    y=['RP Financing $', 'FA Financing $'],
    barmode='group',
    title='Financing Distribution'
)
financing_distribution_chart. update_layout(
    template='plotly_dark',
    font=dict(color='white'),
    title_font_size=20,
    paper_bgcolor='rgba(0, 0, 0, 0)'
)

# Total Financing by Region
region_bar_chart = px.bar(
    region_summary,
    x='Region',
    y='total_financing',
    text='num_countries',
    title='Total Financing by Region',
    labels={
        'total_financing': 'Total Financing $',
        'num_countries': 'Number of Countries'
    },
    color='avg_financing',
    color_continuous_scale='plasma'
)
region_bar_chart.update_traces(
    texttemplate='%{text} countries',
    textposition='outside'
)
region_bar_chart.update_layout(
    template="plotly_dark",
    xaxis_title='Region',
    yaxis_title='Total Financing $'
)

# SIDS and LDCs Bar Chart
sids_ldcs_bar_chart = px.bar(
    sids_ldcs_summary,
    x=['SIDS', 'LDCs'],
    y='total_financing',
    color='num_countries',
    title='SIDS and LDCs Financing'
)
sids_ldcs_bar_chart.update_layout(
    template='plotly_dark',
    font=dict(color='white'),
    title_font_size=20,
    paper_bgcolor='rgba(0, 0, 0, 0)'
)

# RP vs FA Financing
rp_vs_fa_scatter = px.scatter(
    df,
    x="RP Financing $",
    y="FA Financing $",
    size="Total Financing $",
    color="Region",
    title="RP Financing vs FA Financing"
)
rp_vs_fa_scatter.update_layout(
    template="plotly_dark",
    font=dict(color="white"),
    title_font_size=20,
    paper_bgcolor="rgba(0, 0, 0, 0)",
)

# Layout
app.layout = html.Div([
    dcc.Tabs([
        dcc.Tab(label="Map & Distribution", children=[
            html.Div([
                html.P(
                    "RP Financing ($) represents readiness program funding, while FA Financing ($) represents funding approvals for projects.",
                    style={"color": "white", "fontSize": "16px"}
                ),
                html.Div([
                    dcc.Graph(figure=choropleth_map, style={"width": "48%", "display": "inline-block"}),
                    dcc.Graph(figure=financing_distribution_chart, style={"width": "48%", "display": "inline-block"})
                ])
            ])
        ]),
        dcc.Tab(label="SIDS and LDCs", children=[
            html.Div([
                html.P(
                    "SIDS (Small Island Developing States) and LDCs (Least Developed Countries) are vulnerable to climate change and require financial support to address these challenges.",
                    style={"color": "white", "fontSize": "16px"}
                ),
                dcc.Graph(figure=sids_ldcs_bar_chart)
            ])
        ]),
        dcc.Tab(label="RP vs FA Analysis", children=[
            html.Div([
                dcc.Graph(figure=rp_vs_fa_scatter)
            ])
        ]),
        dcc.Tab(label="Regional Analysis", children=[
            html.Div([
                dcc.Graph(figure=region_bar_chart)
            ])
        ])
    ])
], style={"backgroundColor": "black", "padding": "10px"})

if __name__ == '__main__':
    app.run_server(debug=True)