dltmdgus commited on
Commit
cf0ade7
Β·
verified Β·
1 Parent(s): f5047a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -1,54 +1,54 @@
1
- import streamlit as st
2
- import pandas as pd
3
-
4
- # 파일 경둜 μ„€μ •
5
- FILE_PATH = "book_topics_output_modified.xlsx"
6
-
7
- # μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜€λŠ” ν•¨μˆ˜
8
- def load_data(file_path):
9
- return pd.read_excel(file_path)
10
-
11
- # Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜
12
- def main():
13
- st.title("ν‚€μ›Œλ“œ 기반 λ„μ„œ μΆ”μ²œ")
14
-
15
- # 데이터 λ‘œλ“œ
16
- data = load_data(FILE_PATH)
17
-
18
- # μ΅œμ’…ν† ν”½ 열이 μžˆλŠ”μ§€ 확인
19
- if 'μ΅œμ’…ν† ν”½' not in data.columns:
20
- st.error("μ΅œμ’…ν† ν”½ 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
21
- return
22
-
23
- # μ΅œμ’…ν† ν”½ μΉ΄ν…Œκ³ λ¦¬ 선택
24
- topic_category = st.selectbox(
25
- "μ΅œμ’…ν† ν”½μ„ μ„ νƒν•˜μ„Έμš”:",
26
- sorted(data['μ΅œμ’…ν† ν”½'].unique())
27
- )
28
-
29
- # μ„ νƒλœ 토픽에 ν•΄λ‹Ήν•˜λŠ” λ„μ„œ λͺ©λ‘ 필터링
30
- filtered_data = data[data['μ΅œμ’…ν† ν”½'] == topic_category]
31
-
32
- # λ„μ„œλͺ… 열이 μžˆλŠ”μ§€ 확인
33
- if 'λ„μ„œλͺ…' not in data.columns:
34
- st.error("λ„μ„œλͺ… 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
35
- return
36
-
37
- # 숫자 열이 μžˆλŠ”μ§€ 확인
38
- numeric_cols = [col for col in filtered_data.columns if pd.api.types.is_numeric_dtype(filtered_data[col])]
39
- if not numeric_cols:
40
- st.error("숫자 열이 μ—†μŠ΅λ‹ˆλ‹€.")
41
- return
42
-
43
- # κ°€μž₯ 높은 값을 κ°€μ§„ 숫자 μ—΄ 선택
44
- number_col = numeric_cols[0] # 첫 번째 숫자 μ—΄ μ‚¬μš©
45
-
46
- # μƒμœ„ 10개 λ„μ„œλͺ… μΆ”μΆœ
47
- top_books = filtered_data.nlargest(20, number_col)[['λ„μ„œλͺ…', number_col]]
48
-
49
- # λ„μ„œλͺ…λ§Œ 좜λ ₯
50
- st.write(f"μ΅œμ’…ν† ν”½ '{topic_category}'에 ν•΄λ‹Ήν•˜λŠ” μƒμœ„ 10개 λ„μ„œλͺ…:")
51
- st.dataframe(top_books[['λ„μ„œλͺ…']]) # λ„μ„œλͺ…λ§Œ ν‘œμ‹œ
52
-
53
- if __name__ == "__main__":
54
- main()
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ # 파일 경둜 μ„€μ •
5
+ FILE_PATH = "book_topics_output_modified.xlsx"
6
+
7
+ # μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜€λŠ” ν•¨μˆ˜
8
+ def load_data(file_path):
9
+ return pd.read_excel(file_path)
10
+
11
+ # Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜
12
+ def main():
13
+ st.title("ν‚€μ›Œλ“œ 기반 λ„μ„œ μΆ”μ²œ")
14
+
15
+ # 데이터 λ‘œλ“œ
16
+ data = load_data(FILE_PATH)
17
+
18
+ # μ΅œμ’…ν† ν”½ 열이 μžˆλŠ”μ§€ 확인
19
+ if 'μ΅œμ’…ν† ν”½' not in data.columns:
20
+ st.error("μ΅œμ’…ν† ν”½ 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
21
+ return
22
+
23
+ # μ΅œμ’…ν† ν”½ μΉ΄ν…Œκ³ λ¦¬ 선택
24
+ topic_category = st.selectbox(
25
+ "μ΅œμ’…ν† ν”½μ„ μ„ νƒν•˜μ„Έμš”:",
26
+ sorted(data['μ΅œμ’…ν† ν”½'].unique())
27
+ )
28
+
29
+ # μ„ νƒλœ 토픽에 ν•΄λ‹Ήν•˜λŠ” λ„μ„œ λͺ©λ‘ 필터링
30
+ filtered_data = data[data['μ΅œμ’…ν† ν”½'] == topic_category]
31
+
32
+ # λ„μ„œλͺ… 열이 μžˆλŠ”μ§€ 확인
33
+ if 'λ„μ„œλͺ…' not in data.columns:
34
+ st.error("λ„μ„œλͺ… 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
35
+ return
36
+
37
+ # 숫자 열이 μžˆλŠ”μ§€ 확인
38
+ numeric_cols = [col for col in filtered_data.columns if pd.api.types.is_numeric_dtype(filtered_data[col])]
39
+ if not numeric_cols:
40
+ st.error("숫자 열이 μ—†μŠ΅λ‹ˆλ‹€.")
41
+ return
42
+
43
+ # κ°€μž₯ 높은 값을 κ°€μ§„ 숫자 μ—΄ 선택
44
+ number_col = numeric_cols[0] # 첫 번째 숫자 μ—΄ μ‚¬μš©
45
+
46
+ # μƒμœ„ 10개 λ„μ„œλͺ… μΆ”μΆœ
47
+ top_books = filtered_data.nlargest(20, number_col)[['λ„μ„œλͺ…', number_col]]
48
+
49
+ # λ„μ„œλͺ…λ§Œ 좜λ ₯
50
+ st.write(f"μ΅œμ’…ν† ν”½ '{topic_category}'에 ν•΄λ‹Ήν•˜λŠ” μƒμœ„ 20개 λ„μ„œλͺ…:")
51
+ st.dataframe(top_books[['λ„μ„œλͺ…']]) # λ„μ„œλͺ…λ§Œ ν‘œμ‹œ
52
+
53
+ if __name__ == "__main__":
54
+ main()