MSK34 commited on
Commit
a2cfa15
·
verified ·
1 Parent(s): e345fb3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +184 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,186 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+
6
+ st.set_page_config(
7
+ page_title="Olympic Games Data Visualization",
8
+ page_icon="🏅",
9
+ layout="wide"
10
+ )
11
+
12
+ st.title("🏅 Olympic Games Data Visualization")
13
+
14
+ st.write(
15
+ "Bu uygulama, Olimpiyat Oyunları verilerini kullanarak ülke, sporcu, spor dalı, "
16
+ "madalya ve ev sahibi şehirler üzerine görselleştirme analizleri sunar."
17
+ )
18
+
19
+
20
+ @st.cache_data
21
+ def load_data():
22
+ athlete_bio = pd.read_csv("src/Olympic_Athlete_Biography.csv")
23
+ athlete_event = pd.read_csv("src/Olympic_Athlete_Event_Details.csv")
24
+ games = pd.read_csv("src/Olympic_Games_Summary.csv")
25
+ medals = pd.read_csv("src/Olympic_Medal_Tally_History.csv")
26
+ return athlete_bio, athlete_event, games, medals
27
+
28
+
29
+ athlete_bio, athlete_event, games, medals = load_data()
30
+
31
+
32
+ st.sidebar.title("Grafik Seçimi")
33
+
34
+ grafik = st.sidebar.selectbox(
35
+ "Bir grafik seçin:",
36
+ [
37
+ "En Çok Madalya Kazanan Ülkeler",
38
+ "En Fazla Altın Madalya Kazanan Ülkeler",
39
+ "Yıllara Göre Toplam Madalya",
40
+ "En Çok Madalya Kazanılan Spor Dalları",
41
+ "En Çok Madalya Kazanan Sporcular",
42
+ "En Çok Olimpiyat Düzenleyen Şehirler",
43
+ "Yıllara Göre Katılan Ülke Sayısı",
44
+ "Kadın ve Erkek Sporcu Dağılımı"
45
+ ]
46
+ )
47
+
48
+
49
+ if grafik == "En Çok Madalya Kazanan Ülkeler":
50
+ st.subheader("En Çok Madalya Kazanan 15 Ülke")
51
+
52
+ top_countries = (
53
+ medals.groupby("country")["total"]
54
+ .sum()
55
+ .sort_values(ascending=False)
56
+ .head(15)
57
+ )
58
+
59
+ fig, ax = plt.subplots(figsize=(10, 6))
60
+ top_countries.sort_values().plot(kind="barh", ax=ax)
61
+
62
+ ax.set_title("En Çok Madalya Kazanan 15 Ülke")
63
+ ax.set_xlabel("Toplam Madalya")
64
+ ax.set_ylabel("Ülke")
65
+
66
+ st.pyplot(fig)
67
+
68
+
69
+ elif grafik == "En Fazla Altın Madalya Kazanan Ülkeler":
70
+ st.subheader("En Fazla Altın Madalya Kazanan 15 Ülke")
71
+
72
+ top_gold = (
73
+ medals.groupby("country")["gold"]
74
+ .sum()
75
+ .sort_values(ascending=False)
76
+ .head(15)
77
+ )
78
+
79
+ fig, ax = plt.subplots(figsize=(10, 6))
80
+ top_gold.sort_values().plot(kind="barh", ax=ax)
81
+
82
+ ax.set_title("En Fazla Altın Madalya Kazanan 15 Ülke")
83
+ ax.set_xlabel("Altın Madalya")
84
+ ax.set_ylabel("Ülke")
85
+
86
+ st.pyplot(fig)
87
+
88
+
89
+ elif grafik == "Yıllara Göre Toplam Madalya":
90
+ st.subheader("Yıllara Göre Toplam Madalya Sayısı")
91
+
92
+ yearly_medals = medals.groupby("year")["total"].sum()
93
+
94
+ fig, ax = plt.subplots(figsize=(12, 5))
95
+ ax.plot(yearly_medals.index, yearly_medals.values)
96
+
97
+ ax.set_title("Yıllara Göre Toplam Madalya Sayısı")
98
+ ax.set_xlabel("Yıl")
99
+ ax.set_ylabel("Toplam Madalya")
100
+
101
+ st.pyplot(fig)
102
+
103
+
104
+ elif grafik == "En Çok Madalya Kazanılan Spor Dalları":
105
+ st.subheader("En Çok Madalya Kazanılan Spor Dalları")
106
+
107
+ top_sports = (
108
+ athlete_event["sport"]
109
+ .value_counts()
110
+ .head(15)
111
+ )
112
+
113
+ fig, ax = plt.subplots(figsize=(10, 6))
114
+ top_sports.sort_values().plot(kind="barh", ax=ax)
115
+
116
+ ax.set_title("En Çok Madalya Kazanılan Spor Dalları")
117
+ ax.set_xlabel("Madalya Sayısı")
118
+ ax.set_ylabel("Spor Dalı")
119
+
120
+ st.pyplot(fig)
121
+
122
+
123
+ elif grafik == "En Çok Madalya Kazanan Sporcular":
124
+ st.subheader("En Çok Madalya Kazanan Sporcular")
125
+
126
+ top_athletes = (
127
+ athlete_event["athlete"]
128
+ .value_counts()
129
+ .head(15)
130
+ )
131
+
132
+ fig, ax = plt.subplots(figsize=(10, 6))
133
+ top_athletes.sort_values().plot(kind="barh", ax=ax)
134
+
135
+ ax.set_title("En Çok Madalya Kazanan Sporcular")
136
+ ax.set_xlabel("Madalya Sayısı")
137
+ ax.set_ylabel("Sporcu")
138
+
139
+ st.pyplot(fig)
140
+
141
+
142
+ elif grafik == "En Çok Olimpiyat Düzenleyen Şehirler":
143
+ st.subheader("En Çok Olimpiyat Düzenleyen Şehirler")
144
+
145
+ top_city = games["city"].value_counts().head(15)
146
+
147
+ fig, ax = plt.subplots(figsize=(10, 6))
148
+ top_city.sort_values().plot(kind="barh", ax=ax)
149
+
150
+ ax.set_title("En Çok Olimpiyat Düzenleyen Şehirler")
151
+ ax.set_xlabel("Olimpiyat Sayısı")
152
+ ax.set_ylabel("Şehir")
153
+
154
+ st.pyplot(fig)
155
+
156
+
157
+ elif grafik == "Yıllara Göre Katılan Ülke Sayısı":
158
+ st.subheader("Yıllara Göre Katılan Ülke Sayısı")
159
+
160
+ country_per_year = medals.groupby("year")["country"].nunique()
161
+
162
+ fig, ax = plt.subplots(figsize=(12, 5))
163
+ ax.plot(country_per_year.index, country_per_year.values)
164
+
165
+ ax.set_title("Yıllara Göre Katılan Ülke Sayısı")
166
+ ax.set_xlabel("Yıl")
167
+ ax.set_ylabel("Ülke Sayısı")
168
+
169
+ st.pyplot(fig)
170
+
171
+
172
+ elif grafik == "Kadın ve Erkek Sporcu Dağılımı":
173
+ st.subheader("Kadın ve Erkek Sporcu Dağılımı")
174
+
175
+ gender_counts = athlete_bio["sex"].value_counts()
176
+
177
+ fig, ax = plt.subplots(figsize=(7, 7))
178
+ ax.pie(
179
+ gender_counts,
180
+ labels=gender_counts.index,
181
+ autopct="%1.1f%%"
182
+ )
183
+
184
+ ax.set_title("Kadın ve Erkek Sporcu Dağılımı")
185
 
186
+ st.pyplot(fig)