Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +40 -36
src/streamlit_app.py
CHANGED
|
@@ -5,72 +5,76 @@ import plotly.express as px
|
|
| 5 |
# Sayfa Ayarları
|
| 6 |
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 7 |
|
| 8 |
-
# ---
|
| 9 |
-
with st.sidebar:
|
| 10 |
-
st.header("📊 Analysis Notes / Analiz Notları")
|
| 11 |
-
|
| 12 |
-
# 1. Genel Analiz Notları
|
| 13 |
-
st.markdown("""
|
| 14 |
-
**EN:** Analysis shows that developed countries have high GDP and internet usage. It has also been observed that CO2 emissions are high in these countries.
|
| 15 |
-
|
| 16 |
-
**TR:** Analiz sonucunda gelişmiş ülkelerde GDP ve internet kullanımının yüksek olduğu görülmüştür. Aynı zamanda bu ülkelerde CO2 emisyonunun da yüksek olduğu tespit edilmiştir.
|
| 17 |
-
""")
|
| 18 |
-
|
| 19 |
-
st.divider()
|
| 20 |
-
|
| 21 |
-
# 2. GDP SEVİYELERİ AÇIKLAMASI (YENİ EKLEDİĞİMİZ KISIM)
|
| 22 |
-
st.subheader("🔍 What are GDP Levels? / GDP Seviyeleri Nedir?")
|
| 23 |
-
st.markdown("""
|
| 24 |
-
**EN: GDP Categories**
|
| 25 |
-
* **High:** Global economic leaders with massive industrial output.
|
| 26 |
-
* **Medium:** Transitioning economies with growing industries.
|
| 27 |
-
* **Low:** Developing nations with smaller economies.
|
| 28 |
-
|
| 29 |
-
**TR: GDP Kategorileri**
|
| 30 |
-
* **High (Yüksek):** Sanayi üretimi devasa olan, dünya ekonomisine yön veren ülkeler.
|
| 31 |
-
* **Medium (Orta):** Sanayisi büyümekte olan, geçiş aşamasındaki ekonomiler.
|
| 32 |
-
* **Low (Düşük):** Ekonomisi daha küçük, gelişmekte olan ülkeler.
|
| 33 |
-
""")
|
| 34 |
-
|
| 35 |
-
# --- DATA LOAD ---
|
| 36 |
@st.cache_data
|
| 37 |
def load_data():
|
|
|
|
| 38 |
df = pd.read_csv("us_pollution_cleaned.csv")
|
| 39 |
-
# İsimleri Türkçeleştirme ve kısaltma
|
| 40 |
df = df.rename(columns={
|
| 41 |
'country': 'COUNTRY',
|
| 42 |
'GDP: Gross domestic product (million current US$)': 'GDP',
|
| 43 |
'CO2 emission estimates (million tons/tons per capita)': 'CO2'
|
| 44 |
})
|
| 45 |
-
# Gruplandırma (
|
| 46 |
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 47 |
return df
|
| 48 |
|
| 49 |
df = load_data()
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# --- ANA PANEL ---
|
| 52 |
st.title("🌍 World Data Analysis Dashboard")
|
| 53 |
-
st.caption("
|
| 54 |
st.divider()
|
| 55 |
|
| 56 |
-
# 1. HARİTA
|
| 57 |
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
|
| 58 |
fig_map = px.choropleth(df,
|
| 59 |
locations="COUNTRY",
|
| 60 |
locationmode="country names",
|
| 61 |
color="GDP",
|
| 62 |
color_continuous_scale='Viridis',
|
| 63 |
-
labels={'GDP': 'GSYİH (Milyon $)'},
|
| 64 |
height=450)
|
| 65 |
st.plotly_chart(fig_map, use_container_width=True)
|
| 66 |
|
| 67 |
st.divider()
|
| 68 |
|
| 69 |
-
# 2. ALT GRAFİKLER
|
| 70 |
col1, col2 = st.columns(2)
|
| 71 |
|
| 72 |
with col1:
|
| 73 |
-
st.subheader("📊 GDP vs CO2 (Interactive) /GSYİH ve CO2 İlişkisi
|
| 74 |
fig_scatter = px.scatter(df, x="GDP", y="CO2",
|
| 75 |
color="GDP_LEVEL",
|
| 76 |
hover_name="COUNTRY",
|
|
@@ -85,4 +89,4 @@ with col2:
|
|
| 85 |
hole=0.3)
|
| 86 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 87 |
|
| 88 |
-
st.
|
|
|
|
| 5 |
# Sayfa Ayarları
|
| 6 |
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 7 |
|
| 8 |
+
# --- DATA LOAD (Veriyi en başta yüklüyoruz ki sidebar'da kullanabilelim) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@st.cache_data
|
| 10 |
def load_data():
|
| 11 |
+
# Kendi temizlediğin csv dosyan
|
| 12 |
df = pd.read_csv("us_pollution_cleaned.csv")
|
|
|
|
| 13 |
df = df.rename(columns={
|
| 14 |
'country': 'COUNTRY',
|
| 15 |
'GDP: Gross domestic product (million current US$)': 'GDP',
|
| 16 |
'CO2 emission estimates (million tons/tons per capita)': 'CO2'
|
| 17 |
})
|
| 18 |
+
# Gruplandırma (Senin verine göre optimize edildi)
|
| 19 |
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 20 |
return df
|
| 21 |
|
| 22 |
df = load_data()
|
| 23 |
|
| 24 |
+
# --- SIDEBAR (SOL PANEL) ---
|
| 25 |
+
with st.sidebar:
|
| 26 |
+
st.header("📊 Analysis Notes / Analiz Notları")
|
| 27 |
+
|
| 28 |
+
# 1. Genel Notlar
|
| 29 |
+
st.markdown("""
|
| 30 |
+
**EN:** Analysis shows that developed countries have high GDP and internet usage. CO2 emissions are also high in these countries.
|
| 31 |
+
|
| 32 |
+
**TR:** Analiz sonucunda gelişmiş ülkelerde GDP ve internet kullanımının yüksek olduğu görülmüştür. Bu ülkelerde CO2 emisyonu da yüksektir.
|
| 33 |
+
""")
|
| 34 |
+
|
| 35 |
+
st.divider()
|
| 36 |
+
|
| 37 |
+
# 2. GDP SEVİYELERİ VE ÖRNEK ÜLKELER (İstediğin liste burası)
|
| 38 |
+
st.subheader("🔍 GDP Levels & Examples / Seviyeler ve Örnekler")
|
| 39 |
+
|
| 40 |
+
# High Grubu
|
| 41 |
+
high_countries = ", ".join(df[df['GDP_LEVEL'] == 'High']['COUNTRY'].head(4).values)
|
| 42 |
+
st.markdown(f"**🔴 High (Yüksek):** {high_countries}...")
|
| 43 |
+
st.caption("Leaders with massive industries. / Dev sanayiye sahip liderler.")
|
| 44 |
+
|
| 45 |
+
# Medium Grubu
|
| 46 |
+
med_countries = ", ".join(df[df['GDP_LEVEL'] == 'Medium']['COUNTRY'].head(4).values)
|
| 47 |
+
st.markdown(f"**🟡 Medium (Orta):** {med_countries}...")
|
| 48 |
+
st.caption("Growing economies. / Büyümekte olan ekonomiler.")
|
| 49 |
+
|
| 50 |
+
# Low Grubu
|
| 51 |
+
low_countries = ", ".join(df[df['GDP_LEVEL'] == 'Low']['COUNTRY'].head(4).values)
|
| 52 |
+
st.markdown(f"**🟢 Low (Düşük):** {low_countries}...")
|
| 53 |
+
st.caption("Developing nations. / Gelişmekte olan ülkeler.")
|
| 54 |
+
|
| 55 |
# --- ANA PANEL ---
|
| 56 |
st.title("🌍 World Data Analysis Dashboard")
|
| 57 |
+
st.caption("Data Analysis and Visualization / Veri Analizi ve Görselleştirme")
|
| 58 |
st.divider()
|
| 59 |
|
| 60 |
+
# 1. HARİTA (Map)
|
| 61 |
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
|
| 62 |
fig_map = px.choropleth(df,
|
| 63 |
locations="COUNTRY",
|
| 64 |
locationmode="country names",
|
| 65 |
color="GDP",
|
| 66 |
color_continuous_scale='Viridis',
|
| 67 |
+
labels={'GDP': 'GSYİH (Milyon $)'},
|
| 68 |
height=450)
|
| 69 |
st.plotly_chart(fig_map, use_container_width=True)
|
| 70 |
|
| 71 |
st.divider()
|
| 72 |
|
| 73 |
+
# 2. ALT GRAFİKLER (Scatter ve Pie)
|
| 74 |
col1, col2 = st.columns(2)
|
| 75 |
|
| 76 |
with col1:
|
| 77 |
+
st.subheader("📊 GDP vs CO2 (Interactive) / GSYİH ve CO2 İlişkisi")
|
| 78 |
fig_scatter = px.scatter(df, x="GDP", y="CO2",
|
| 79 |
color="GDP_LEVEL",
|
| 80 |
hover_name="COUNTRY",
|
|
|
|
| 89 |
hole=0.3)
|
| 90 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 91 |
|
| 92 |
+
st.success("✅ Dashboard successfully loaded. / Panel başarıyla yüklendi.")
|