Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +26 -20
src/streamlit_app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
-
import plotly.graph_objects as go
|
| 5 |
|
| 6 |
# Sayfa Ayarları
|
| 7 |
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
|
@@ -9,33 +8,41 @@ st.set_page_config(page_title="World Data Analysis", layout="wide")
|
|
| 9 |
# --- SIDEBAR (SOL PANEL) ---
|
| 10 |
with st.sidebar:
|
| 11 |
st.header("📊 Analysis Notes / Analiz Notları")
|
|
|
|
|
|
|
| 12 |
st.markdown("""
|
| 13 |
-
**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.
|
| 14 |
|
| 15 |
-
**
|
| 16 |
-
* **High GDP & CO2:** USA, China, Germany.
|
| 17 |
-
* **Low Income & Energy:** Afghanistan, Yemen, Zambia.
|
| 18 |
""")
|
|
|
|
| 19 |
st.divider()
|
|
|
|
|
|
|
|
|
|
| 20 |
st.markdown("""
|
| 21 |
-
**
|
| 22 |
-
|
| 23 |
-
**
|
| 24 |
-
* **
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
""")
|
| 27 |
|
| 28 |
# --- DATA LOAD ---
|
| 29 |
-
@st.cache_data
|
| 30 |
def load_data():
|
| 31 |
df = pd.read_csv("us_pollution_cleaned.csv")
|
| 32 |
-
#
|
| 33 |
df = df.rename(columns={
|
| 34 |
'country': 'COUNTRY',
|
| 35 |
'GDP: Gross domestic product (million current US$)': 'GDP',
|
| 36 |
'CO2 emission estimates (million tons/tons per capita)': 'CO2'
|
| 37 |
})
|
| 38 |
-
#
|
| 39 |
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 40 |
return df
|
| 41 |
|
|
@@ -46,37 +53,36 @@ st.title("🌍 World Data Analysis Dashboard")
|
|
| 46 |
st.caption("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
|
| 47 |
st.divider()
|
| 48 |
|
| 49 |
-
# 1. HARİTA
|
| 50 |
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
|
| 51 |
fig_map = px.choropleth(df,
|
| 52 |
locations="COUNTRY",
|
| 53 |
locationmode="country names",
|
| 54 |
color="GDP",
|
| 55 |
color_continuous_scale='Viridis',
|
|
|
|
| 56 |
height=450)
|
| 57 |
st.plotly_chart(fig_map, use_container_width=True)
|
| 58 |
|
| 59 |
st.divider()
|
| 60 |
|
| 61 |
-
# 2. ALT GRAFİKLER
|
| 62 |
col1, col2 = st.columns(2)
|
| 63 |
|
| 64 |
with col1:
|
| 65 |
st.subheader("📊 GDP vs CO2 (Interactive)")
|
| 66 |
-
# Artık noktaların üzerine gelebilirsin!
|
| 67 |
fig_scatter = px.scatter(df, x="GDP", y="CO2",
|
| 68 |
color="GDP_LEVEL",
|
| 69 |
hover_name="COUNTRY",
|
|
|
|
| 70 |
template="plotly_white")
|
| 71 |
st.plotly_chart(fig_scatter, use_container_width=True)
|
| 72 |
|
| 73 |
with col2:
|
| 74 |
-
st.subheader("🍕 GDP Level Distribution")
|
| 75 |
-
# Pasta grafiği de artık tıklanabilir
|
| 76 |
fig_pie = px.pie(df, names='GDP_LEVEL', values='GDP',
|
| 77 |
color_discrete_sequence=px.colors.sequential.RdBu,
|
| 78 |
hole=0.3)
|
| 79 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 80 |
|
| 81 |
-
st.
|
| 82 |
-
st.write("✅ Proje tamamlandı. Tüm grafikler etkileşimlidir.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
|
|
|
| 4 |
|
| 5 |
# Sayfa Ayarları
|
| 6 |
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
|
|
|
| 8 |
# --- SIDEBAR (SOL PANEL) ---
|
| 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 (Bins değerlerini senin verine göre ayarladım)
|
| 46 |
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 47 |
return df
|
| 48 |
|
|
|
|
| 53 |
st.caption("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
|
| 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 $)'}, # Etiketi Türkçeleştirdik
|
| 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)")
|
|
|
|
| 74 |
fig_scatter = px.scatter(df, x="GDP", y="CO2",
|
| 75 |
color="GDP_LEVEL",
|
| 76 |
hover_name="COUNTRY",
|
| 77 |
+
labels={'GDP': 'GSYİH', 'CO2': 'CO2 Emisyonu', 'GDP_LEVEL': 'Gelir Grubu'},
|
| 78 |
template="plotly_white")
|
| 79 |
st.plotly_chart(fig_scatter, use_container_width=True)
|
| 80 |
|
| 81 |
with col2:
|
| 82 |
+
st.subheader("🍕 GDP Level Distribution / Gelir Dağılımı")
|
|
|
|
| 83 |
fig_pie = px.pie(df, names='GDP_LEVEL', values='GDP',
|
| 84 |
color_discrete_sequence=px.colors.sequential.RdBu,
|
| 85 |
hole=0.3)
|
| 86 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 87 |
|
| 88 |
+
st.write("✅ Veri temizleme ve görselleştirme başarıyla tamamlandı.")
|
|
|