File size: 1,821 Bytes
8721276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt
from matplotlib import font_manager as fm

# ํฐํŠธ ํŒŒ์ผ ๊ฒฝ๋กœ ์„ค์ •
font_path = r"C:\Users\user\Desktop\๋„์„œ๊ด€_๊ณต๋ชจ์ „\์ตœ์ข…\H2GTRM.TTF"

# ํฐํŠธ ๋“ฑ๋ก
font_prop = fm.FontProperties(fname=font_path)
plt.rcParams['font.family'] = font_prop.get_name()

# Excel ํŒŒ์ผ ๊ฒฝ๋กœ
excel_path = "C:/Users/user/Desktop/๋„์„œ๊ด€_๊ณต๋ชจ์ „/์ตœ์ข…/12_๋‹ค๋Œ€์ถœ๊ทธ๋ฃน/๋„์„œ ๋Œ€์ถœ ํŒจํ„ด ๋ถ„์„/์ƒ์œ„_5_๋„์„œ.xlsx"

# Excel ํŒŒ์ผ์˜ ์‹œํŠธ๋“ค์„ ์ฝ์–ด์˜ค๊ธฐ
@st.cache_data
def load_excel_sheets(file_path):
    xls = pd.ExcelFile(file_path)
    sheets = {}
    for sheet_name in xls.sheet_names:
        sheets[sheet_name] = pd.read_excel(xls, sheet_name)
    return sheets

sheets = load_excel_sheets(excel_path)
sheet_names = list(sheets.keys())

# Streamlit ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
st.title('์—ฐ๋ น/์„ฑ๋ณ„์— ๋”ฐ๋ฅธ ์ƒ์œ„ 5๊ฐœ ๋Œ€์ถœ ๋„์„œ')


# ์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ
selected_category = st.selectbox('์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์„ ํƒํ•˜์„ธ์š”:', sheet_names)

# ์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ์˜ Excel ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
df = sheets[selected_category]

# ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„ ํ™•์ธ
st.write(f'์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {selected_category}')
st.dataframe(df)

# ๋ฐ์ดํ„ฐ ํ”„๋ ˆ์ž„์—์„œ ์ƒ์œ„ 5๊ฐœ ๋„์„œ์™€ ๋Œ€์ถœ ๊ฑด์ˆ˜ ์ถ”์ถœ
top_5_books = df.head(5)

# ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
fig, ax = plt.subplots(figsize=(10, 6))  # ๊ทธ๋ž˜ํ”„ ํฌ๊ธฐ ์กฐ์ •
ax.bar(top_5_books['๋„์„œ๋ช…'], top_5_books['๋Œ€์ถœ๊ฑด์ˆ˜'])

# ๋ ˆ์ด๋ธ” ํšŒ์ „ ๋ฐ ๋ ˆ์ด๋ธ” ๊ฐ„๊ฒฉ ์กฐ์ •
ax.set_xlabel('๋„์„œ๋ช…')
ax.set_ylabel('๋Œ€์ถœ๊ฑด์ˆ˜')
ax.set_title(f'{selected_category} - ์ƒ์œ„ 5๊ฐœ ๋„์„œ ๋Œ€์ถœ ๊ฑด์ˆ˜')

# X์ถ• ๋ ˆ์ด๋ธ” ํšŒ์ „
plt.xticks(rotation=45, ha='right')

# Streamlit์—์„œ ๊ทธ๋ž˜ํ”„ ํ‘œ์‹œ
st.pyplot(fig)