File size: 1,691 Bytes
a2dcc43
5488719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf0ade7
 
5488719
 
 
 
cf0ade7
5488719
 
 
 
 
cf0ade7
5488719
 
cf0ade7
5488719
 
cf0ade7
 
 
5488719
 
 
cf0ade7
 
5488719
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
import pandas as pd


# 파일 경둜 μ„€μ •
FILE_PATH = "book_topics_output_modified.xlsx"

# μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜€λŠ” ν•¨μˆ˜
def load_data(file_path):
    return pd.read_excel(file_path)

# Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜
def main():
    st.title("ν‚€μ›Œλ“œ 기반 λ„μ„œ μΆ”μ²œ")

    # 데이터 λ‘œλ“œ
    data = load_data(FILE_PATH)

    # μ΅œμ’…ν† ν”½ 열이 μžˆλŠ”μ§€ 확인
    if 'μ΅œμ’…ν† ν”½' not in data.columns:
        st.error("μ΅œμ’…ν† ν”½ 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
        return

    # μ΅œμ’…ν† ν”½ μΉ΄ν…Œκ³ λ¦¬ 선택
    topic_category = st.selectbox(
        "μ΅œμ’…ν† ν”½μ„ μ„ νƒν•˜μ„Έμš”:",
        sorted(data['μ΅œμ’…ν† ν”½'].unique())
    )

    # μ„ νƒλœ 토픽에 ν•΄λ‹Ήν•˜λŠ” λ„μ„œ λͺ©λ‘ 필터링
    filtered_data = data[data['μ΅œμ’…ν† ν”½'] == topic_category]


    # λ„μ„œλͺ… 열이 μžˆλŠ”μ§€ 확인
    if 'λ„μ„œλͺ…' not in data.columns:
        st.error("λ„μ„œλͺ… 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
        return

    # 숫자 열이 μžˆλŠ”μ§€ 확인
    numeric_cols = [col for col in filtered_data.columns if pd.api.types.is_numeric_dtype(filtered_data[col])]
    if not numeric_cols:
        st.error("숫자 열이 μ—†μŠ΅λ‹ˆλ‹€.")
        return

    # κ°€μž₯ 높은 값을 κ°€μ§„ 숫자 μ—΄ 선택
    number_col = numeric_cols[0]  # 첫 번째 숫자 μ—΄ μ‚¬μš©

    # μƒμœ„ 10개 λ„μ„œλͺ… μΆ”μΆœ
    top_books = filtered_data.nlargest(20, number_col)[['λ„μ„œλͺ…', number_col]]



    # λ„μ„œλͺ…λ§Œ 좜λ ₯
    st.write(f"μ΅œμ’…ν† ν”½ '{topic_category}'에 ν•΄λ‹Ήν•˜λŠ” μƒμœ„ 20개 λ„μ„œλͺ…:")
    st.dataframe(top_books[['λ„μ„œλͺ…']])  # λ„μ„œλͺ…λ§Œ ν‘œμ‹œ


if __name__ == "__main__":
    main()