World-Data-Analysis / src /streamlit_app.py
ESMATUGBA's picture
Update src/streamlit_app.py
21ed593 verified
Raw
History Blame
3.23 kB
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
import matplotlib.pyplot as plt
# Sayfa Ayarları
st.set_page_config(page_title="World Data Analysis", layout="wide")
# --- SIDEBAR (SOL TARAF) - SENİN METNİN ---
st.sidebar.header("📊 Analysis Notes / Analiz Notları")
# İngilizce Notlar
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
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")
except:
st.error("Dosya bulunamadı! / File not found!")
st.stop()
# Sütun isimlerini veriye göre eşleştirme
df = df.rename(columns={
'country': 'COUNTRY',
'GDP: Gross domestic product (million current US$)': 'GDP',
'CO2 emission estimates (million tons/tons per capita)': 'CO2'
})
# GDP_LEVEL Sütununu Güncelleme
if 'GDP' in df.columns:
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], 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 ---
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"}
))
fig_map.update_layout(height=400, margin={"r":0,"t":0,"l":0,"b":0})
st.plotly_chart(fig_map, use_container_width=True)
st.divider()
# --- 2. ALT GRAFİKLER (YAN YANA) ---
col1, col2 = st.columns(2)
with col1:
st.subheader("📊 GDP vs CO2")
fig1, ax1 = plt.subplots(figsize=(5, 4))
ax1.scatter(df['GDP'], df['CO2'], color='royalblue', alpha=0.6, s=20)
ax1.set_xlabel("GDP")
ax1.set_ylabel("CO2")
st.pyplot(fig1)
with col2:
st.subheader("Pie Chart / Gelir Seviyesi Dağılımı")
fig2, ax2 = plt.subplots(figsize=(5, 4))
df_pie = df['GDP_LEVEL'].value_counts()
ax2.pie(df_pie, labels=df_pie.index, autopct='%1.1f%%', colors=['#ff9999','#66b3ff','#99ff99'])
st.pyplot(fig2)
st.divider()
st.write("✅ Proje tamamlandı / Project completed")