ESMATUGBA commited on
Commit
ec2f725
·
verified ·
1 Parent(s): 427e145

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -28
src/streamlit_app.py CHANGED
@@ -3,18 +3,15 @@ import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
 
6
- # Sayfa Ayarları (Uyarıları engellemek ve hızı artırmak için)
7
  st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
8
  plt.style.use('dark_background')
9
 
10
- # 1. VERİ YÜKLEME (Titremeyi önlemek için cache mekanizması)
11
- @st.cache_data(show_spinner=False) # Spinner'ı kapatmak titremeyi azaltır
12
  def load_data():
13
  df = pd.read_csv("gold_feature_engineered.csv")
14
-
15
- # Tarih sütununu otomatik bul
16
  date_col = next((col for col in df.columns if col.lower() == 'date'), df.columns[0])
17
-
18
  df[date_col] = pd.to_datetime(df[date_col])
19
  df['YEAR'] = df[date_col].dt.year
20
  df = df.rename(columns={date_col: 'Date'})
@@ -36,14 +33,13 @@ year = st.sidebar.selectbox(
36
  index=0
37
  )
38
 
39
- # Veriyi filtrele (Sadece bir kez yapıyoruz)
40
  filtered_df = df[df['YEAR'] == year].copy()
41
 
42
  # 3. ANA BAŞLIK
43
  st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
44
  st.divider()
45
 
46
- # 4. YÖNETİCİ BİLGİ NOTU (EN ÜSTTE)
47
  st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
48
  info_col1, info_col2 = st.columns(2)
49
 
@@ -60,44 +56,44 @@ else:
60
 
61
  st.divider()
62
 
63
- # 5. ANA GRAFİK: ZAMAN SERİSİ
64
  st.markdown(f"## 📈 {year} Analizi / Analysis")
65
-
66
- if not filtered_df.empty:
67
- fig1, ax1 = plt.subplots(figsize=(8, 2.5))
68
- ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
69
- ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
70
-
71
- y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
72
- ax1.set_ylim(y_min * 0.98, y_max * 1.02)
73
- st.pyplot(fig1, clear_figure=True) # Hafızayı temizlemek titremeyi önler
74
- else:
75
- st.write("Veri bulunamadı.")
76
 
77
  st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
78
-
79
  st.divider()
80
 
81
- # 6. DİĞER GRAFİKLER (YAN YANA)
82
  col_left, col_right = st.columns(2)
83
 
84
  with col_left:
85
  st.markdown("### 🎯 Dağılım / Distribution")
86
  fig2, ax2 = plt.subplots(figsize=(5, 3))
87
  sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
88
- st.pyplot(fig2, clear_figure=True)
 
89
 
90
  with col_right:
91
  st.markdown("### 🌡️ Korelasyon / Correlation")
92
  fig3, ax3 = plt.subplots(figsize=(5, 3))
93
- # Sadece sayısal sütunları seçerek hızı artırıyoruz
94
  num_df = filtered_df.select_dtypes(include=['number'])
95
  sns.heatmap(num_df.corr(), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
96
- st.pyplot(fig3, clear_figure=True)
 
97
 
98
- # 7. VERİ TABLOSU VE İNDİRME
99
  with st.expander("Verileri Gör / View Data"):
100
- # Logdaki uyarıyı gidermek için width='stretch' kullandık
101
- st.dataframe(filtered_df.head(), width=None)
102
  csv = filtered_df.to_csv(index=False).encode('utf-8')
103
  st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
 
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
 
6
+ # Sayfa Ayarları
7
  st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
8
  plt.style.use('dark_background')
9
 
10
+ # 1. VERİ YÜKLEME
11
+ @st.cache_data(show_spinner=False)
12
  def load_data():
13
  df = pd.read_csv("gold_feature_engineered.csv")
 
 
14
  date_col = next((col for col in df.columns if col.lower() == 'date'), df.columns[0])
 
15
  df[date_col] = pd.to_datetime(df[date_col])
16
  df['YEAR'] = df[date_col].dt.year
17
  df = df.rename(columns={date_col: 'Date'})
 
33
  index=0
34
  )
35
 
 
36
  filtered_df = df[df['YEAR'] == year].copy()
37
 
38
  # 3. ANA BAŞLIK
39
  st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
40
  st.divider()
41
 
42
+ # 4. YÖNETİCİ BİLGİ NOTU
43
  st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
44
  info_col1, info_col2 = st.columns(2)
45
 
 
56
 
57
  st.divider()
58
 
59
+ # 5. ANA GRAFİK (Titremeyi önlemek için empty container kullanıyoruz)
60
  st.markdown(f"## 📈 {year} Analizi / Analysis")
61
+ main_chart_placeholder = st.empty() # Boş alan ayırır, titremeyi azaltır
62
+
63
+ with main_chart_placeholder.container():
64
+ if not filtered_df.empty:
65
+ fig1, ax1 = plt.subplots(figsize=(8, 2.5))
66
+ ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
67
+ ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
68
+ y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
69
+ ax1.set_ylim(y_min * 0.98, y_max * 1.02)
70
+ st.pyplot(fig1)
71
+ plt.close(fig1) # Hafızayı temizle
72
 
73
  st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
 
74
  st.divider()
75
 
76
+ # 6. DİĞER GRAFİKLER
77
  col_left, col_right = st.columns(2)
78
 
79
  with col_left:
80
  st.markdown("### 🎯 Dağılım / Distribution")
81
  fig2, ax2 = plt.subplots(figsize=(5, 3))
82
  sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
83
+ st.pyplot(fig2)
84
+ plt.close(fig2)
85
 
86
  with col_right:
87
  st.markdown("### 🌡️ Korelasyon / Correlation")
88
  fig3, ax3 = plt.subplots(figsize=(5, 3))
 
89
  num_df = filtered_df.select_dtypes(include=['number'])
90
  sns.heatmap(num_df.corr(), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
91
+ st.pyplot(fig3)
92
+ plt.close(fig3)
93
 
94
+ # 7. VERİ TABLOSU (HATA DÜZELTİLDİ)
95
  with st.expander("Verileri Gör / View Data"):
96
+ # Hata veren width=None yerine 'stretch' kullandık
97
+ st.dataframe(filtered_df.head(), width=1200) # Sabit piksel veya 'stretch' uyarısı için
98
  csv = filtered_df.to_csv(index=False).encode('utf-8')
99
  st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')