Spaces:
No application file
No application file
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)
|