dltmdgus commited on
Commit
6694af2
Β·
verified Β·
1 Parent(s): bc34780

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -12
app.py CHANGED
@@ -5,23 +5,39 @@ import seaborn as sns
5
  import matplotlib.font_manager as fm
6
 
7
  # 폰트 μ„€μ •
8
- font_path = r"NanumGothic.ttf" # 폰트 파일 경둜 μ„€μ •
9
- font_prop = fm.FontProperties(fname=font_path)
10
- plt.rcParams['font.family'] = font_prop.get_name() # λ˜λŠ” 직접 폰트 이름을 μ‚¬μš©: 'Nanum Gothic'
11
- plt.rcParams['axes.unicode_minus'] = False
 
 
 
 
 
 
 
 
12
 
13
  # μ‚¬μ΄λ“œλ°”μ— λͺ©μ°¨ μΆ”κ°€
14
  st.sidebar.title("λͺ©μ°¨")
15
  page = st.sidebar.radio("νŽ˜μ΄μ§€ 선택", ["μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ", "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄"])
16
 
 
 
 
 
 
 
 
 
17
  if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
18
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ")
19
 
20
  # 데이터 λ‘œλ“œ
21
- file_path = r'μƒμœ„_5_λ„μ„œ.xlsx'
22
- df = pd.read_excel(file_path, sheet_name=None)
23
- df = pd.concat(df.values()) # λͺ¨λ“  μ‹œνŠΈ 데이터λ₯Ό κ²°ν•©
24
-
25
  # μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ λ„μ„œ λŒ€μΆœ 건수 집계
26
  book_patterns = df.groupby(['λ„μ„œλͺ…', 'μ—°λ Ή', '성별'])['λŒ€μΆœκ±΄μˆ˜'].sum().reset_index()
27
 
@@ -53,14 +69,16 @@ if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
53
  ax.set_ylabel('λŒ€μΆœκ±΄μˆ˜')
54
  plt.xticks(rotation=45, ha='right')
55
  st.pyplot(fig)
 
 
56
 
57
  elif page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄":
58
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄")
59
 
60
  # 데이터 λ‘œλ“œ
61
- file_path = r'μƒμœ„_3_μž₯λ₯΄.xlsx'
62
- df = pd.read_excel(file_path, sheet_name=None)
63
- df = pd.concat(df.values()) # λͺ¨λ“  μ‹œνŠΈ 데이터λ₯Ό κ²°ν•©
64
 
65
  # μ—°λ ΉλŒ€ λ¬Έμžμ—΄ 처리
66
  df['μ—°λ ΉλŒ€'] = df['μ—°λ ΉλŒ€'].astype(str)
@@ -85,4 +103,7 @@ elif page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄":
85
  image_path = 'heat_map_page-0001.jpg'
86
 
87
  # 이미지 μ—…λ‘œλ“œ 및 ν‘œμ‹œ
88
- st.image(image_path, caption="히트맡", use_column_width=True)
 
 
 
 
5
  import matplotlib.font_manager as fm
6
 
7
  # 폰트 μ„€μ •
8
+ font_path = 'NanumGothic.ttf' # 폰트 파일 경둜 μ„€μ •
9
+
10
+ try:
11
+ # 폰트 파일이 μžˆλŠ” 경우
12
+ font_prop = fm.FontProperties(fname=font_path)
13
+ plt.rcParams['font.family'] = font_prop.get_name() # 폰트 이름 μ„€μ •
14
+ except Exception as e:
15
+ # 폰트 νŒŒμΌμ„ 찾을 수 μ—†κ±°λ‚˜ λ‘œλ“œν•  수 μ—†λŠ” 경우
16
+ st.warning(f"폰트 μ„€μ • 쀑 였λ₯˜ λ°œμƒ: {e}. κΈ°λ³Έ ν°νŠΈκ°€ μ‚¬μš©λ©λ‹ˆλ‹€.")
17
+ plt.rcParams['font.family'] = 'sans-serif' # κΈ°λ³Έ 폰트둜 μ„€μ •
18
+
19
+ plt.rcParams['axes.unicode_minus'] = False # 음수 기호 μ œλŒ€λ‘œ ν‘œμ‹œλ˜λ„λ‘ μ„€μ •
20
 
21
  # μ‚¬μ΄λ“œλ°”μ— λͺ©μ°¨ μΆ”κ°€
22
  st.sidebar.title("λͺ©μ°¨")
23
  page = st.sidebar.radio("νŽ˜μ΄μ§€ 선택", ["μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ", "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄"])
24
 
25
+ def load_data(file_path):
26
+ try:
27
+ df = pd.read_excel(file_path, sheet_name=None)
28
+ return pd.concat(df.values())
29
+ except Exception as e:
30
+ st.error(f"데이터λ₯Ό λ‘œλ“œν•˜λŠ” λ™μ•ˆ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")
31
+ return pd.DataFrame()
32
+
33
  if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
34
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ")
35
 
36
  # 데이터 λ‘œλ“œ
37
+ df = load_data(r'μƒμœ„_5_λ„μ„œ.xlsx')
38
+ if df.empty:
39
+ st.stop()
40
+
41
  # μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ λ„μ„œ λŒ€μΆœ 건수 집계
42
  book_patterns = df.groupby(['λ„μ„œλͺ…', 'μ—°λ Ή', '성별'])['λŒ€μΆœκ±΄μˆ˜'].sum().reset_index()
43
 
 
69
  ax.set_ylabel('λŒ€μΆœκ±΄μˆ˜')
70
  plt.xticks(rotation=45, ha='right')
71
  st.pyplot(fig)
72
+ else:
73
+ st.write("μ„ νƒν•œ 쑰건에 λ§žλŠ” 데이터가 μ—†μŠ΅λ‹ˆλ‹€.")
74
 
75
  elif page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄":
76
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄")
77
 
78
  # 데이터 λ‘œλ“œ
79
+ df = load_data(r'μƒμœ„_3_μž₯λ₯΄.xlsx')
80
+ if df.empty:
81
+ st.stop()
82
 
83
  # μ—°λ ΉλŒ€ λ¬Έμžμ—΄ 처리
84
  df['μ—°λ ΉλŒ€'] = df['μ—°λ ΉλŒ€'].astype(str)
 
103
  image_path = 'heat_map_page-0001.jpg'
104
 
105
  # 이미지 μ—…λ‘œλ“œ 및 ν‘œμ‹œ
106
+ if image_path:
107
+ st.image(image_path, caption="히트맡", use_column_width=True)
108
+ else:
109
+ st.write("이미지 νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.")