Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,102 +1,89 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import plotly.graph_objects as go
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
|
| 6 |
-
# Sayfa
|
| 7 |
-
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 8 |
-
|
| 9 |
-
# --- SIDEBAR (SOL TARAF) ---
|
| 10 |
-
st.sidebar.header("📊 Analysis Notes / Analiz Notları")
|
| 11 |
-
|
| 12 |
-
# İngilizce Notlar
|
| 13 |
-
st.sidebar.markdown("""
|
| 14 |
-
**EN:** Analysis shows that developed countries have high GDP and internet usage.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.sidebar.markdown("
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
**
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
st.
|
| 52 |
-
st.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
# --- 1. HARİTA
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
st.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
st.pyplot(
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
st.subheader("Pie Chart / Gelir Seviyesi Dağılımı")
|
| 90 |
-
# figsize=(4, 3) ile çok daha küçük bir ebat
|
| 91 |
-
fig2, ax2 = plt.subplots(figsize=(4, 3))
|
| 92 |
-
df['GDP_LEVEL'].value_counts().plot.pie(
|
| 93 |
-
autopct='%1.1f%%',
|
| 94 |
-
ax=ax2,
|
| 95 |
-
colors=['#ff9999','#66b3ff','#99ff99'],
|
| 96 |
-
textprops={'fontsize': 8} # Yüzde yazılarını küçültür
|
| 97 |
-
)
|
| 98 |
-
ax2.set_ylabel("") # Yan taraftaki etiketi siler
|
| 99 |
-
st.pyplot(fig2)
|
| 100 |
-
|
| 101 |
-
st.divider()
|
| 102 |
st.write("✅ Proje tamamlandı / Project completed")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Sayfa Ayarları
|
| 7 |
+
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 8 |
+
|
| 9 |
+
# --- SIDEBAR (SOL TARAF) - SENİN METNİN ---
|
| 10 |
+
st.sidebar.header("📊 Analysis Notes / Analiz Notları")
|
| 11 |
+
|
| 12 |
+
# İngilizce Notlar
|
| 13 |
+
st.sidebar.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. 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.
|
| 15 |
+
|
| 16 |
+
**Examples:**
|
| 17 |
+
* **High GDP & CO2:** USA, China, Germany.
|
| 18 |
+
* **Low Income & Energy:** Afghanistan, Yemen, Zambia.
|
| 19 |
+
""")
|
| 20 |
+
|
| 21 |
+
st.sidebar.markdown("---") # Ayırıcı çizgi
|
| 22 |
+
|
| 23 |
+
# Türkçe Notlar
|
| 24 |
+
st.sidebar.markdown("""
|
| 25 |
+
**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.
|
| 26 |
+
|
| 27 |
+
**Örnekler:**
|
| 28 |
+
* **Yüksek GDP & CO2:** ABD (USA), Çin (China), Almanya.
|
| 29 |
+
* **Düşük Gelir & Enerji:** Afganistan, Yemen, Zambiya.
|
| 30 |
+
""")
|
| 31 |
+
|
| 32 |
+
# --- DATA LOAD ---
|
| 33 |
+
try:
|
| 34 |
+
df = pd.read_csv("us_pollution_cleaned.csv")
|
| 35 |
+
except:
|
| 36 |
+
st.error("Dosya bulunamadı! / File not found!")
|
| 37 |
+
st.stop()
|
| 38 |
+
|
| 39 |
+
# Sütun isimlerini veriye göre eşleştirme
|
| 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 |
+
|
| 46 |
+
# GDP_LEVEL Sütununu Güncelleme
|
| 47 |
+
if 'GDP' in df.columns:
|
| 48 |
+
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 49 |
+
|
| 50 |
+
# --- ANA SAYFA BAŞLIK ---
|
| 51 |
+
st.title("🌍 World Data Analysis Dashboard / Dünya Veri Analizi Paneli")
|
| 52 |
+
st.write("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
|
| 53 |
+
st.divider()
|
| 54 |
+
|
| 55 |
+
# --- 1. HARİTA ---
|
| 56 |
+
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
|
| 57 |
+
fig_map = go.Figure(data=dict(
|
| 58 |
+
type="choropleth",
|
| 59 |
+
colorscale='Viridis',
|
| 60 |
+
locations=df["COUNTRY"],
|
| 61 |
+
locationmode="country names",
|
| 62 |
+
z=df["GDP"],
|
| 63 |
+
colorbar={'title': "GDP"}
|
| 64 |
+
))
|
| 65 |
+
fig_map.update_layout(height=400, margin={"r":0,"t":0,"l":0,"b":0})
|
| 66 |
+
st.plotly_chart(fig_map, use_container_width=True)
|
| 67 |
+
|
| 68 |
+
st.divider()
|
| 69 |
+
|
| 70 |
+
# --- 2. ALT GRAFİKLER (YAN YANA) ---
|
| 71 |
+
col1, col2 = st.columns(2)
|
| 72 |
+
|
| 73 |
+
with col1:
|
| 74 |
+
st.subheader("📊 GDP vs CO2")
|
| 75 |
+
fig1, ax1 = plt.subplots(figsize=(5, 4))
|
| 76 |
+
ax1.scatter(df['GDP'], df['CO2'], color='royalblue', alpha=0.6, s=20)
|
| 77 |
+
ax1.set_xlabel("GDP")
|
| 78 |
+
ax1.set_ylabel("CO2")
|
| 79 |
+
st.pyplot(fig1)
|
| 80 |
+
|
| 81 |
+
with col2:
|
| 82 |
+
st.subheader("Pie Chart / Gelir Seviyesi Dağılımı")
|
| 83 |
+
fig2, ax2 = plt.subplots(figsize=(5, 4))
|
| 84 |
+
df_pie = df['GDP_LEVEL'].value_counts()
|
| 85 |
+
ax2.pie(df_pie, labels=df_pie.index, autopct='%1.1f%%', colors=['#ff9999','#66b3ff','#99ff99'])
|
| 86 |
+
st.pyplot(fig2)
|
| 87 |
+
|
| 88 |
+
st.divider()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
st.write("✅ Proje tamamlandı / Project completed")
|