And app that compares economic data for European countries
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
# Set page config
st.set_page_config(page_title="EU Economic Comparison", layout="wide")
# Title and description
st.title("European Economic Indicators Comparison")
st.write("Compare key economic indicators across European countries")
# Load the data
@st.cache_data
def load_data():
# World Bank data for EU countries (2021)
data = {
'Country': [
'Germany', 'France', 'Italy', 'Spain', 'Netherlands',
'Poland', 'Sweden', 'Belgium', 'Austria', 'Ireland',
'Denmark', 'Finland', 'Greece', 'Portugal', 'Czech Republic'
],
'GDP_Billions': [
4223.12, 2937.47, 2099.88, 1425.28, 1012.84,
674.05, 627.44, 594.10, 477.08, 498.56,
398.30, 297.30, 214.87, 253.66, 281.78
],
'GDP_Per_Capita': [
50788, 45028, 35551, 30103, 58061,
17840, 60239, 51096, 53637, 99239,
68007, 53654, 20192, 24711, 26378
],
'Unemployment_Rate': [
3.5, 7.9, 9.5, 14.8, 4.2,
3.4, 8.8, 6.3, 6.0, 6.2,
5.1, 7.7, 14.8, 6.9, 2.8
],
'Inflation_Rate': [
3.2, 2.1, 1.9, 3.0, 2.7,
5.1, 2.2, 3.2, 2.8, 2.4,
1.9, 2.2, 1.2, 1.3, 3.8
]
}
return pd.DataFrame(data)
df = load_data()
# Sidebar controls
st.sidebar.header("Select Indicators")
indicator = st.sidebar.selectbox(
"Choose Economic Indicator",
["GDP_Billions", "GDP_Per_Capita", "Unemployment_Rate", "Inflation_Rate"],
format_func=lambda x: x.replace("_", " ")
)
selected_countries = st.sidebar.multiselect(
"Select Countries to Compare",
df['Country'].tolist(),
default=df['Country'].head(5).tolist()
)
# Main content
if not selected_countries:
st.warning("Please select at least one country from the sidebar.")
else:
# Filter data based on selection
filtered_df = df[df['Country'].isin(selected_countries)]
# Create visualization
fig = px.bar(
filtered_df,
x='Country',
y=indicator,
title=f"{indicator.replace('_', ' ')} by Country",
color='Country'
)
fig.update_layout(
xaxis_title="Country",
yaxis_title=indicator.replace('_', ' '),
showlegend=False
)
st.plotly_chart(fig, use_container_width=True)
# Display data table
st.subheader("Detailed Data")
st.dataframe(
filtered_df.style.highlight_max(axis=0, props='background-color: #90EE90'),
hide_index=True
)
# Summary statistics
st.subheader("Summary Statistics")
col1, col2, col3 = st.columns(3)
with col1:
st.metric(
"Highest Value",
f"{filtered_df[indicator].max():,.2f}",
f"Country: {filtered_df.loc[filtered_df[indicator].idxmax(), 'Country']}"
)
with col2:
st.metric(
"Lowest Value",
f"{filtered_df[indicator].min():,.2f}",
f"Country: {filtered_df.loc[filtered_df[indicator].idxmin(), 'Country']}"
)
with col3:
st.metric(
"Average",
f"{filtered_df[indicator].mean():,.2f}"
)
# Footer
st.markdown("---")
st.markdown(
"""
Data source: Sample data based on World Bank indicators (2021)
Note: This is simplified demo data for illustration purposes.
"""
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?