ESMATUGBA commited on
Commit
21ed593
·
verified ·
1 Parent(s): 96a90bb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -40
src/streamlit_app.py CHANGED
@@ -3,18 +3,15 @@ import pandas as pd
3
  import plotly.graph_objects as go
4
  import matplotlib.pyplot as plt
5
 
6
- # Sayfa Genişliği ve Ayarlar
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 (Üstte)
13
  st.sidebar.markdown("""
14
- **EN:** Analysis shows that developed countries have high GDP and internet usage.
15
- It has also been observed that CO2 emissions are high in these countries.
16
- In low-income countries, energy and internet usage are found to be lower.
17
- In some cases, an inverse relationship between forest rate and CO2 emissions has been seen.
18
 
19
  **Examples:**
20
  * **High GDP & CO2:** USA, China, Germany.
@@ -23,12 +20,9 @@ In some cases, an inverse relationship between forest rate and CO2 emissions has
23
 
24
  st.sidebar.markdown("---") # Ayırıcı çizgi
25
 
26
- # Türkçe Notlar (Altta)
27
  st.sidebar.markdown("""
28
- **TR:** Analiz sonucunda gelişmiş ülkelerde GDP ve internet kullanımının yüksek olduğu görülmüştür.
29
- Aynı zamanda bu ülkelerde CO2 emisyonunun da yüksek olduğu tespit edilmiştir.
30
- Düşük gelirli ülkelerde ise enerji ve internet kullanımının daha düşük olduğu gözlemlenmiştir.
31
- Orman oranı ile CO2 emisyonu arasında bazı durumlarda ters ilişki olduğu görülmüştür.
32
 
33
  **Örnekler:**
34
  * **Yüksek GDP & CO2:** ABD (USA), Çin (China), Almanya.
@@ -37,23 +31,28 @@ Orman oranı ile CO2 emisyonu arasında bazı durumlarda ters ilişki olduğu g
37
 
38
  # --- DATA LOAD ---
39
  try:
40
- df = pd.read_csv("us_pollution_cleaned.csv") # Dosya adını kontrol et!
41
  except:
42
  st.error("Dosya bulunamadı! / File not found!")
43
  st.stop()
44
 
45
- # GDP_LEVEL Sütununu Oluşturma (Emin olmak için)
46
- if 'GDP' in df.columns and 'GDP_LEVEL' not in df.columns:
47
- df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 2000, 10000, 100000], labels=['Low', 'Medium', 'High'])
 
 
 
 
 
 
 
48
 
49
  # --- ANA SAYFA BAŞLIK ---
50
  st.title("🌍 World Data Analysis Dashboard / Dünya Veri Analizi Paneli")
51
  st.write("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
52
  st.divider()
53
 
54
- # ==========================================
55
- # --- 1. HARİTA (EN ÜSTTE VE GENİŞ) ---
56
- # ==========================================
57
  st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
58
  fig_map = go.Figure(data=dict(
59
  type="choropleth",
@@ -63,39 +62,27 @@ fig_map = go.Figure(data=dict(
63
  z=df["GDP"],
64
  colorbar={'title': "GDP"}
65
  ))
66
- # Haritayı biraz daha basık yapıyoruz (yüksekliği 350)
67
- fig_map.update_layout(height=350, margin={"r":0,"t":0,"l":0,"b":0})
68
  st.plotly_chart(fig_map, use_container_width=True)
69
 
70
  st.divider()
71
 
72
- # ==========================================
73
- # --- 2. KÜÇÜK GRAFİKLER (ALTTAN VE YAN YANA) ---
74
- # ==========================================
75
  col1, col2 = st.columns(2)
76
 
77
  with col1:
78
  st.subheader("📊 GDP vs CO2")
79
- # figsize=(4, 3) ile çok daha küçük bir ebat
80
- fig1, ax1 = plt.subplots(figsize=(4, 3))
81
- ax1.scatter(df['GDP'], df['CO2'], color='royalblue', alpha=0.6, s=15) # s=15 noktaları küçültür
82
- ax1.set_xlabel("GDP", fontsize=10)
83
- ax1.set_ylabel("CO2", fontsize=10)
84
- # Eksen yazılarını küçültme
85
- ax1.tick_params(axis='both', which='major', labelsize=8)
86
  st.pyplot(fig1)
87
 
88
  with col2:
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()
 
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.
 
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.
 
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",
 
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()