Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,89 +1,82 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import plotly.
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
# Sayfa Ayarları
|
| 7 |
-
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 8 |
-
|
| 9 |
-
# --- SIDEBAR (SOL
|
| 10 |
-
st.sidebar
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
**
|
| 17 |
-
* **
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
fig_map =
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
with
|
| 74 |
-
st.subheader("
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
st.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 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")
|
|
|
|
| 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")
|
| 8 |
+
|
| 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. 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.
|
| 14 |
+
|
| 15 |
+
**Examples:**
|
| 16 |
+
* **High GDP & CO2:** USA, China, Germany.
|
| 17 |
+
* **Low Income & Energy:** Afghanistan, Yemen, Zambia.
|
| 18 |
+
""")
|
| 19 |
+
st.divider()
|
| 20 |
+
st.markdown("""
|
| 21 |
+
**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.
|
| 22 |
+
|
| 23 |
+
**Örnekler:**
|
| 24 |
+
* **Yüksek GDP & CO2:** ABD (USA), Çin (China), Almanya.
|
| 25 |
+
* **Düşük Gelir & Enerji:** Afganistan, Yemen, Zambiya.
|
| 26 |
+
""")
|
| 27 |
+
|
| 28 |
+
# --- DATA LOAD ---
|
| 29 |
+
@st.cache_data # Titremeyi engellemek için veriyi hafızaya alır
|
| 30 |
+
def load_data():
|
| 31 |
+
df = pd.read_csv("us_pollution_cleaned.csv")
|
| 32 |
+
# Sütun isimlerini kısaltma
|
| 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 |
+
# GDP_LEVEL oluşturma
|
| 39 |
+
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 50000, 1000000, 30000000], labels=['Low', 'Medium', 'High'])
|
| 40 |
+
return df
|
| 41 |
+
|
| 42 |
+
df = load_data()
|
| 43 |
+
|
| 44 |
+
# --- ANA PANEL ---
|
| 45 |
+
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 (Plotly Express - Daha hızlı ve etkileşimli)
|
| 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 (Yan Yana ve İnteraktif)
|
| 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.divider()
|
| 82 |
+
st.write("✅ Proje tamamlandı. Tüm grafikler etkileşimlidir.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|