World-Data-Analysis / src /streamlit_app.py
ESMATUGBA's picture
Update src/streamlit_app.py
6190c0d verified
Raw
History Blame
3.76 kB
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
import matplotlib.pyplot as plt
# Sayfa Genişliği ve Ayarlar
st.set_page_config(page_title="World Data Analysis", layout="wide")
# --- SIDEBAR (SOL TARAF) ---
st.sidebar.header("📊 Analysis Notes / Analiz Notları")
# İngilizce Notlar (Üstte)
st.sidebar.markdown("""
**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.
In low-income countries, energy and internet usage are found to be lower.
In some cases, an inverse relationship between forest rate and CO2 emissions has been seen.
**Examples:**
* **High GDP & CO2:** USA, China, Germany.
* **Low Income & Energy:** Afghanistan, Yemen, Zambia.
""")
st.sidebar.markdown("---") # Ayırıcı çizgi
# Türkçe Notlar (Altta)
st.sidebar.markdown("""
**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.
Düşük gelirli ülkelerde ise enerji ve internet kullanımının daha düşük olduğu gözlemlenmiştir.
Orman oranı ile CO2 emisyonu arasında bazı durumlarda ters ilişki olduğu görülmüştür.
**Örnekler:**
* **Yüksek GDP & CO2:** ABD (USA), Çin (China), Almanya.
* **Düşük Gelir & Enerji:** Afganistan, Yemen, Zambiya.
""")
# --- DATA LOAD ---
try:
df = pd.read_csv("us_pollution_cleaned.csv") # Dosya adını kontrol et!
except:
st.error("Dosya bulunamadı! / File not found!")
st.stop()
# GDP_LEVEL Sütununu Oluşturma (Emin olmak için)
if 'GDP' in df.columns and 'GDP_LEVEL' not in df.columns:
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 2000, 10000, 100000], labels=['Low', 'Medium', 'High'])
# --- ANA SAYFA BAŞLIK ---
st.title("🌍 World Data Analysis Dashboard / Dünya Veri Analizi Paneli")
st.write("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
st.divider()
# ==========================================
# --- 1. HARİTA (EN ÜSTTE VE GENİŞ) ---
# ==========================================
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
fig_map = go.Figure(data=dict(
type="choropleth",
colorscale='Viridis',
locations=df["COUNTRY"],
locationmode="country names",
z=df["GDP"],
colorbar={'title': "GDP"}
))
# Haritayı biraz daha basık yapıyoruz (yüksekliği 350)
fig_map.update_layout(height=350, margin={"r":0,"t":0,"l":0,"b":0})
st.plotly_chart(fig_map, use_container_width=True)
st.divider()
# ==========================================
# --- 2. KÜÇÜK GRAFİKLER (ALTTAN VE YAN YANA) ---
# ==========================================
col1, col2 = st.columns(2)
with col1:
st.subheader("📊 GDP vs CO2")
# figsize=(4, 3) ile çok daha küçük bir ebat
fig1, ax1 = plt.subplots(figsize=(4, 3))
ax1.scatter(df['GDP'], df['CO2'], color='royalblue', alpha=0.6, s=15) # s=15 noktaları küçültür
ax1.set_xlabel("GDP", fontsize=10)
ax1.set_ylabel("CO2", fontsize=10)
# Eksen yazılarını küçültme
ax1.tick_params(axis='both', which='major', labelsize=8)
st.pyplot(fig1)
with col2:
st.subheader("Pie Chart / Gelir Seviyesi Dağılımı")
# figsize=(4, 3) ile çok daha küçük bir ebat
fig2, ax2 = plt.subplots(figsize=(4, 3))
df['GDP_LEVEL'].value_counts().plot.pie(
autopct='%1.1f%%',
ax=ax2,
colors=['#ff9999','#66b3ff','#99ff99'],
textprops={'fontsize': 8} # Yüzde yazılarını küçültür
)
ax2.set_ylabel("") # Yan taraftaki etiketi siler
st.pyplot(fig2)
st.divider()
st.write("✅ Proje tamamlandı / Project completed")