dltmdgus commited on
Commit
8f434a7
ยท
verified ยท
1 Parent(s): b62897c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -27
app.py CHANGED
@@ -1,18 +1,25 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
- from matplotlib.font_manager import FontProperties
6
 
7
  # Streamlit ํŽ˜์ด์ง€ ์„ค์ •
8
  st.set_page_config(page_title="๋„์„œ ๋Œ€์ถœ ์ˆ˜์š” ์˜ˆ์ธก", layout="wide")
9
 
10
- # ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
11
- st.sidebar.title("์ด๋ฏธ์ง€ ๋ณด๊ธฐ")
 
 
12
  image1 = "image-1.jpeg"
13
  image2 = "image-2.jpeg"
14
- st.sidebar.image(image1, caption="์ด๋ฏธ์ง€ 1", use_column_width=True)
15
- st.sidebar.image(image2, caption="์ด๋ฏธ์ง€ 2", use_column_width=True)
 
 
 
 
 
 
 
16
 
17
  # ์—‘์…€ ํŒŒ์ผ ๊ฒฝ๋กœ
18
  file_path = r'book_analysis_summary.xlsx'
@@ -20,10 +27,7 @@ file_path = r'book_analysis_summary.xlsx'
20
  # ์—‘์…€ ํŒŒ์ผ ์ฝ๊ธฐ
21
  df = pd.read_excel(file_path)
22
 
23
- # Streamlit ์•ฑ ์ œ๋ชฉ
24
- st.title("๋„์„œ ๋Œ€์ถœ ์˜ˆ์ธก ๋ถ„์„")
25
-
26
- # ์—ฐ๋ น_์„ฑ๋ณ„ ์—ด์„ ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ฃนํ™”
27
  group_column = '์—ฐ๋ น_์„ฑ๋ณ„'
28
  if group_column in df.columns:
29
  st.sidebar.title("๊ทธ๋ฃน ์„ ํƒ")
@@ -33,22 +37,27 @@ if group_column in df.columns:
33
  # ์„ ํƒ๋œ ๊ทธ๋ฃน์˜ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
34
  filtered_data = df[df[group_column] == selected_group]
35
 
36
- # ํฐํŠธ ์„ค์ •
37
- font_path = "H2GTRM.TTF" # ํฐํŠธ ํŒŒ์ผ ๊ฒฝ๋กœ
38
- font_prop = FontProperties(fname=font_path)
39
 
40
- # ํฐํŠธ ์†์„ฑ ์„ค์ •
41
- plt.rcParams['font.family'] = font_prop.get_name() # ํฐํŠธ ์„ค์ •
42
- plt.rcParams['font.size'] = 12 # ๊ธฐ๋ณธ ํฐํŠธ ํฌ๊ธฐ ์„ค์ •
43
 
44
- fig, ax = plt.subplots(figsize=(10, 6))
45
- sns.barplot(data=filtered_data, x='์—ฐ๋ น_์„ฑ๋ณ„', y='์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜', ax=ax, color='blue', label='์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜')
46
- sns.barplot(data=filtered_data, x='์—ฐ๋ น_์„ฑ๋ณ„', y='์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜', ax=ax, color='red', label='์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜')
47
- ax.set_title(f'์˜ˆ์ธก ๋Œ€์ถœ ๊ฑด์ˆ˜ vs ์‹ค์ œ ๋Œ€์ถœ ๊ฑด์ˆ˜ ({selected_group})')
48
- ax.set_xlabel('์—ฐ๋ น๋Œ€ ๋ฐ ์„ฑ๋ณ„')
49
- ax.set_ylabel('๋Œ€์ถœ ๊ฑด์ˆ˜')
50
- ax.legend()
51
- plt.xticks(rotation=45)
 
 
 
 
 
 
 
52
 
53
- # Matplotlib ๊ทธ๋ž˜ํ”„๋ฅผ Streamlit์—์„œ ๋ Œ๋”๋ง
54
- st.pyplot(fig)
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import altair as alt
 
 
4
 
5
  # Streamlit ํŽ˜์ด์ง€ ์„ค์ •
6
  st.set_page_config(page_title="๋„์„œ ๋Œ€์ถœ ์ˆ˜์š” ์˜ˆ์ธก", layout="wide")
7
 
8
+ # ํŽ˜์ด์ง€์— ์ด๋ฏธ์ง€ ๋‚˜๋ž€ํžˆ ํ‘œ์‹œ
9
+ st.title("๋„์„œ ๋Œ€์ถœ ์˜ˆ์ธก ๋ถ„์„")
10
+
11
+ # ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ
12
  image1 = "image-1.jpeg"
13
  image2 = "image-2.jpeg"
14
+
15
+ # ๋‘ ๊ฐœ์˜ ์ด๋ฏธ์ง€๋ฅผ ๋‚˜๋ž€ํžˆ ๋ฐฐ์น˜
16
+ col1, col2 = st.columns(2)
17
+
18
+ with col1:
19
+ st.image(image1, caption="์ด๋ฏธ์ง€ 1", use_column_width=True)
20
+
21
+ with col2:
22
+ st.image(image2, caption="์ด๋ฏธ์ง€ 2", use_column_width=True)
23
 
24
  # ์—‘์…€ ํŒŒ์ผ ๊ฒฝ๋กœ
25
  file_path = r'book_analysis_summary.xlsx'
 
27
  # ์—‘์…€ ํŒŒ์ผ ์ฝ๊ธฐ
28
  df = pd.read_excel(file_path)
29
 
30
+ # ๊ทธ๋ฃน ์„ ํƒ
 
 
 
31
  group_column = '์—ฐ๋ น_์„ฑ๋ณ„'
32
  if group_column in df.columns:
33
  st.sidebar.title("๊ทธ๋ฃน ์„ ํƒ")
 
37
  # ์„ ํƒ๋œ ๊ทธ๋ฃน์˜ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
38
  filtered_data = df[df[group_column] == selected_group]
39
 
40
+ # ํ•„์š”ํ•œ ์—ด๋งŒ ์ถ”์ถœ (์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜, ์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜)
41
+ filtered_data = filtered_data[['์—ฐ๋ น_์„ฑ๋ณ„', '์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜', '์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜']]
 
42
 
43
+ # ํ•„ํ„ฐ๋ง๋œ ๋ฐ์ดํ„ฐ ํ‘œ์‹œ
44
+ st.write(f"์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {selected_group}")
45
+ st.write(filtered_data)
46
 
47
+ # ๋ฐ์ดํ„ฐ๋ฅผ ์„ธ๋กœ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋กœ ์‹œ๊ฐํ™”
48
+ chart_data = filtered_data.melt(id_vars='์—ฐ๋ น_์„ฑ๋ณ„', var_name='Type', value_name='Count')
49
+
50
+ bar_chart = alt.Chart(chart_data).mark_bar().encode(
51
+ x=alt.X('์—ฐ๋ น_์„ฑ๋ณ„:N', title='์—ฐ๋ น๋Œ€ ๋ฐ ์„ฑ๋ณ„'),
52
+ y=alt.Y('Count:Q', title='๋Œ€์ถœ๊ฑด์ˆ˜'),
53
+ color='Type:N',
54
+ column='Type:N'
55
+ ).properties(
56
+ width=300,
57
+ height=400
58
+ ).configure_axis(
59
+ labelFontSize=12,
60
+ titleFontSize=14
61
+ )
62
 
63
+ st.altair_chart(bar_chart, use_container_width=True)