Spaces:
No application file
No application file
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 ํ์ผ์ ์ํธ๋ค์ ์ฝ์ด์ค๊ธฐ | |
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) | |