Update app.py
Browse files
app.py
CHANGED
|
@@ -24,21 +24,23 @@ continents_excl_world = ['Asia', 'Oceania', 'Europe', 'Africa', 'North America',
|
|
| 24 |
@pn.depends(year_slider.param.value, yaxis_co2.param.value)
|
| 25 |
def get_co2_plot(year, yaxis):
|
| 26 |
co2_pipeline = df[(df.year <= year) & (df.country.isin(continents))].groupby(['country', 'year'])[yaxis].mean().reset_index()
|
|
|
|
|
|
|
| 27 |
co2_pipeline = co2_pipeline.rename(columns={'country': 'continent'})
|
| 28 |
|
| 29 |
plot = co2_pipeline.hvplot(
|
| 30 |
x='year',
|
| 31 |
-
by='continent',
|
| 32 |
y=yaxis,
|
| 33 |
line_width=2,
|
| 34 |
title="CO2 emission by continent",
|
| 35 |
-
height=
|
| 36 |
-
width=
|
| 37 |
legend='right',
|
| 38 |
fontscale=0.8,
|
| 39 |
padding=0.1,
|
| 40 |
grid=True,
|
| 41 |
-
hover_cols=['continent', 'year', yaxis]
|
| 42 |
).opts(
|
| 43 |
legend_position='right',
|
| 44 |
show_grid=True,
|
|
@@ -56,19 +58,19 @@ def get_co2_plot(year, yaxis):
|
|
| 56 |
@pn.depends(year_slider.param.value, yaxis_co2.param.value)
|
| 57 |
def get_co2_table(year, yaxis):
|
| 58 |
co2_pipeline = df[(df.year <= year) & (df.country.isin(continents))].groupby(['country', 'year'])[yaxis].mean().reset_index()
|
| 59 |
-
return pn.widgets.Tabulator(co2_pipeline, pagination='remote', page_size=5, sizing_mode='stretch_width', height=150, margin=(0, 0, 0,
|
| 60 |
|
| 61 |
@pn.depends(year_slider.param.value)
|
| 62 |
def get_co2_vs_gdp_scatterplot(year):
|
| 63 |
scatterplot_pipeline = df[(df.year == year) & (~df.country.isin(continents))].groupby(['country', 'year', 'gdp_per_capita'])['co2'].mean().reset_index()
|
| 64 |
-
return scatterplot_pipeline.hvplot(x='gdp_per_capita', y='co2', by='country', size=
|
| 65 |
|
| 66 |
@pn.depends(year_slider.param.value, yaxis_co2_source.param.value)
|
| 67 |
def get_co2_source_bar_plot(year, yaxis):
|
| 68 |
continent_abbr = {'Africa': 'AF', 'Asia': 'AS', 'Europe': 'EU', 'North America': 'NA', 'South America': 'SA', 'Oceania': 'OC', 'Antarctica': 'AN'}
|
| 69 |
bar_pipeline = df[(df.year == year) & (df.country.isin(continents_excl_world))].groupby(['year', 'country'])[yaxis].sum().reset_index()
|
| 70 |
bar_pipeline['country'] = bar_pipeline['country'].map(continent_abbr)
|
| 71 |
-
return bar_pipeline.hvplot(kind='bar', x='country', y=yaxis, title='CO2 source by continent', height=
|
| 72 |
|
| 73 |
template = pn.template.FastListTemplate(
|
| 74 |
title='World CO2 Emission Dashboard',
|
|
@@ -103,3 +105,4 @@ pn.extension(sizing_mode="stretch_both")
|
|
| 103 |
template.servable()
|
| 104 |
|
| 105 |
|
|
|
|
|
|
| 24 |
@pn.depends(year_slider.param.value, yaxis_co2.param.value)
|
| 25 |
def get_co2_plot(year, yaxis):
|
| 26 |
co2_pipeline = df[(df.year <= year) & (df.country.isin(continents))].groupby(['country', 'year'])[yaxis].mean().reset_index()
|
| 27 |
+
|
| 28 |
+
# Renombrar la columna 'country' a 'continent'
|
| 29 |
co2_pipeline = co2_pipeline.rename(columns={'country': 'continent'})
|
| 30 |
|
| 31 |
plot = co2_pipeline.hvplot(
|
| 32 |
x='year',
|
| 33 |
+
by='continent', # Cambiado de 'country' a 'continent'
|
| 34 |
y=yaxis,
|
| 35 |
line_width=2,
|
| 36 |
title="CO2 emission by continent",
|
| 37 |
+
height=300,
|
| 38 |
+
width=500,
|
| 39 |
legend='right',
|
| 40 |
fontscale=0.8,
|
| 41 |
padding=0.1,
|
| 42 |
grid=True,
|
| 43 |
+
hover_cols=['continent', 'year', yaxis] # Actualizado para usar 'continent'
|
| 44 |
).opts(
|
| 45 |
legend_position='right',
|
| 46 |
show_grid=True,
|
|
|
|
| 58 |
@pn.depends(year_slider.param.value, yaxis_co2.param.value)
|
| 59 |
def get_co2_table(year, yaxis):
|
| 60 |
co2_pipeline = df[(df.year <= year) & (df.country.isin(continents))].groupby(['country', 'year'])[yaxis].mean().reset_index()
|
| 61 |
+
return pn.widgets.Tabulator(co2_pipeline, pagination='remote', page_size=5, sizing_mode='stretch_width', height=150, margin=(0, 0, 0, 0))
|
| 62 |
|
| 63 |
@pn.depends(year_slider.param.value)
|
| 64 |
def get_co2_vs_gdp_scatterplot(year):
|
| 65 |
scatterplot_pipeline = df[(df.year == year) & (~df.country.isin(continents))].groupby(['country', 'year', 'gdp_per_capita'])['co2'].mean().reset_index()
|
| 66 |
+
return scatterplot_pipeline.hvplot(x='gdp_per_capita', y='co2', by='country', size=40, kind="scatter", alpha=0.7, fontscale=0.7, legend=False, height=200, width=450)
|
| 67 |
|
| 68 |
@pn.depends(year_slider.param.value, yaxis_co2_source.param.value)
|
| 69 |
def get_co2_source_bar_plot(year, yaxis):
|
| 70 |
continent_abbr = {'Africa': 'AF', 'Asia': 'AS', 'Europe': 'EU', 'North America': 'NA', 'South America': 'SA', 'Oceania': 'OC', 'Antarctica': 'AN'}
|
| 71 |
bar_pipeline = df[(df.year == year) & (df.country.isin(continents_excl_world))].groupby(['year', 'country'])[yaxis].sum().reset_index()
|
| 72 |
bar_pipeline['country'] = bar_pipeline['country'].map(continent_abbr)
|
| 73 |
+
return bar_pipeline.hvplot(kind='bar', x='country', y=yaxis, title='CO2 source by continent', height=250, width=450, xlabel='Continent', fontscale=0.7, margin=(0, 0, 0, 0))
|
| 74 |
|
| 75 |
template = pn.template.FastListTemplate(
|
| 76 |
title='World CO2 Emission Dashboard',
|
|
|
|
| 105 |
template.servable()
|
| 106 |
|
| 107 |
|
| 108 |
+
|