Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,48 +3,34 @@ import pandas as pd
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
import matplotlib.font_manager as fm
|
| 6 |
-
from
|
| 7 |
-
from io import BytesIO
|
| 8 |
|
| 9 |
# ํฐํธ ์ค์
|
| 10 |
-
font_path = r"H2GTRM.TTF"
|
| 11 |
font_prop = fm.FontProperties(fname=font_path, size=12)
|
| 12 |
plt.rcParams['font.family'] = font_prop.get_name()
|
| 13 |
plt.rcParams['axes.unicode_minus'] = False
|
| 14 |
|
| 15 |
# ์ฌ์ด๋๋ฐ์ ๋ชฉ์ฐจ ์ถ๊ฐ
|
| 16 |
st.sidebar.title("๋ชฉ์ฐจ")
|
| 17 |
-
page = st.sidebar.radio("ํ์ด์ง ์ ํ", ["
|
| 18 |
|
| 19 |
-
if page == "
|
| 20 |
-
st.title("
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
book_patterns = df.groupby(['๋์๋ช
'])['๋์ถ๊ฑด์'].sum().reset_index()
|
| 28 |
-
|
| 29 |
-
# ์์ 10๊ฐ ๋์ ์ถ์ถ
|
| 30 |
-
top_books = book_patterns.nlargest(10, '๋์ถ๊ฑด์')
|
| 31 |
-
|
| 32 |
-
# ์์ 10๊ฐ์ ๋์ ์๊ฐํ
|
| 33 |
-
st.write("์์ 10๊ฐ ๋์ถ ๋์")
|
| 34 |
-
fig, ax = plt.subplots(figsize=(12, 8))
|
| 35 |
-
sns.barplot(data=top_books, x='๋์๋ช
', y='๋์ถ๊ฑด์', palette='viridis', ax=ax)
|
| 36 |
-
ax.set_title('๋ชจ๋ ๋์ถ ๋์ ์์ 10๊ฐ')
|
| 37 |
-
ax.set_xlabel('๋์๋ช
')
|
| 38 |
-
ax.set_ylabel('๋์ถ๊ฑด์')
|
| 39 |
-
plt.xticks(rotation=45, ha='right')
|
| 40 |
-
st.pyplot(fig)
|
| 41 |
|
| 42 |
-
elif page == "
|
| 43 |
-
st.title("
|
| 44 |
|
| 45 |
# ๋ฐ์ดํฐ ๋ก๋
|
| 46 |
-
file_path = r'
|
| 47 |
-
df = pd.read_excel(file_path, sheet_name=
|
|
|
|
| 48 |
|
| 49 |
# ์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ๋์ ๋์ถ ๊ฑด์ ์ง๊ณ
|
| 50 |
book_patterns = df.groupby(['๋์๋ช
', '์ฐ๋ น', '์ฑ๋ณ'])['๋์ถ๊ฑด์'].sum().reset_index()
|
|
@@ -76,12 +62,13 @@ elif page == "๊ฒฐ๊ณผ 2":
|
|
| 76 |
plt.xticks(rotation=45, ha='right')
|
| 77 |
st.pyplot(fig)
|
| 78 |
|
| 79 |
-
elif page == "
|
| 80 |
-
st.title("
|
| 81 |
|
| 82 |
# ๋ฐ์ดํฐ ๋ก๋
|
| 83 |
-
file_path = r'
|
| 84 |
-
df = pd.read_excel(file_path, sheet_name=
|
|
|
|
| 85 |
|
| 86 |
# ์ฐ๋ น๋ ๋ฌธ์์ด ์ฒ๋ฆฌ
|
| 87 |
df['์ฐ๋ น๋'] = df['์ฐ๋ น'].astype(str)
|
|
@@ -95,38 +82,9 @@ elif page == "๊ฒฐ๊ณผ 3":
|
|
| 95 |
sns.heatmap(genre_age_sex, annot=False, cmap='YlGnBu', linewidths=0.5, ax=ax)
|
| 96 |
ax.set_title('์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์ฅ๋ฅด ์ ํธ๋')
|
| 97 |
st.pyplot(fig)
|
| 98 |
-
|
| 99 |
-
# ์์ 3๊ฐ์ ์ฃผ์ ๋ถ๋ฅ๋ช
์ถ์ถ
|
| 100 |
-
top_genres = df.groupby(['์ฐ๋ น๋', '์ฑ๋ณ', '์ฃผ์ ๋ถ๋ฅ๋ช
'])['๋์ถ๊ฑด์'].sum().reset_index()
|
| 101 |
-
top_genres = top_genres.sort_values(by=['์ฐ๋ น๋', '์ฑ๋ณ', '๋์ถ๊ฑด์'], ascending=[True, True, False])
|
| 102 |
-
top_3_genres = top_genres.groupby(['์ฐ๋ น๋', '์ฑ๋ณ']).head(3).reset_index(drop=True)
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
| 106 |
-
genders = top_3_genres['์ฑ๋ณ'].unique()
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
filtered_genres = top_3_genres[(top_3_genres['์ฐ๋ น๋'] == selected_age) & (top_3_genres['์ฑ๋ณ'] == selected_gender)]
|
| 112 |
-
|
| 113 |
-
# ๋ง๋ ๊ทธ๋ํ ์๊ฐํ
|
| 114 |
-
if not filtered_genres.empty:
|
| 115 |
-
st.write(f"์์ 3 ์ฅ๋ฅด (์ฐ๋ น๋: {selected_age}, ์ฑ๋ณ: {selected_gender})")
|
| 116 |
-
fig, ax = plt.subplots(figsize=(10, 6))
|
| 117 |
-
sns.barplot(data=filtered_genres, x='์ฃผ์ ๋ถ๋ฅ๏ฟฝ๏ฟฝ', y='๋์ถ๊ฑด์', palette='viridis', ax=ax)
|
| 118 |
-
ax.set_title(f'{selected_age} - {selected_gender}์ ์์ 3 ์ฅ๋ฅด')
|
| 119 |
-
ax.set_xlabel('์ฃผ์ ๋ถ๋ฅ๋ช
')
|
| 120 |
-
ax.set_ylabel('๋์ถ๊ฑด์')
|
| 121 |
-
plt.xticks(rotation=45, ha='right')
|
| 122 |
-
st.pyplot(fig)
|
| 123 |
-
|
| 124 |
-
# ์์ 3 ์ฅ๋ฅด PDF ๋ค์ด๋ก๋
|
| 125 |
-
pdf_path = r'C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\6_๋์๋์ถ ํจํด ๋ถ์\์์_3_์ฅ๋ฅด.pdf'
|
| 126 |
-
with open(pdf_path, "rb") as f:
|
| 127 |
-
st.download_button(
|
| 128 |
-
label="์์ 3 ์ฅ๋ฅด PDF ๋ค์ด๋ก๋",
|
| 129 |
-
data=f,
|
| 130 |
-
file_name="์์_3_์ฅ๋ฅด.pdf",
|
| 131 |
-
mime="application/pdf"
|
| 132 |
-
)
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import seaborn as sns
|
| 5 |
import matplotlib.font_manager as fm
|
| 6 |
+
from PIL import Image
|
|
|
|
| 7 |
|
| 8 |
# ํฐํธ ์ค์
|
| 9 |
+
font_path = r"C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\H2GTRM.TTF"
|
| 10 |
font_prop = fm.FontProperties(fname=font_path, size=12)
|
| 11 |
plt.rcParams['font.family'] = font_prop.get_name()
|
| 12 |
plt.rcParams['axes.unicode_minus'] = False
|
| 13 |
|
| 14 |
# ์ฌ์ด๋๋ฐ์ ๋ชฉ์ฐจ ์ถ๊ฐ
|
| 15 |
st.sidebar.title("๋ชฉ์ฐจ")
|
| 16 |
+
page = st.sidebar.radio("ํ์ด์ง ์ ํ", ["๋ชจ๋ ๋์ถ ๋์ ์์ 10๊ฐ", "์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 5๊ฐ ๋์ถ ๋์", "์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 3๊ฐ ์ฅ๋ฅด"])
|
| 17 |
|
| 18 |
+
if page == "๋ชจ๋ ๋์ถ ๋์ ์์ 10๊ฐ":
|
| 19 |
+
st.title("๋ชจ๋ ๋์ถ ๋์ ์์ 10๊ฐ")
|
| 20 |
|
| 21 |
+
# ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก
|
| 22 |
+
image_path = r'C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\6_๋์๋์ถ ํจํด ๋ถ์\top_books_plot_page-0001.jpg'
|
| 23 |
+
|
| 24 |
+
# ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ํ์
|
| 25 |
+
st.image(image_path, caption="๋ชจ๋ ๋์ถ ๋์ ์์ 10๊ฐ", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
elif page == "์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 5๊ฐ ๋์ถ ๋์":
|
| 28 |
+
st.title("์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 5๊ฐ ๋์ถ ๋์")
|
| 29 |
|
| 30 |
# ๋ฐ์ดํฐ ๋ก๋
|
| 31 |
+
file_path = r'C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\6_๋์๋์ถ ํจํด ๋ถ์\์์_5_๋์.xlsx'
|
| 32 |
+
df = pd.read_excel(file_path, sheet_name=None)
|
| 33 |
+
df = pd.concat(df.values()) # ๋ชจ๋ ์ํธ ๋ฐ์ดํฐ๋ฅผ ๊ฒฐํฉ
|
| 34 |
|
| 35 |
# ์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ๋์ ๋์ถ ๊ฑด์ ์ง๊ณ
|
| 36 |
book_patterns = df.groupby(['๋์๋ช
', '์ฐ๋ น', '์ฑ๋ณ'])['๋์ถ๊ฑด์'].sum().reset_index()
|
|
|
|
| 62 |
plt.xticks(rotation=45, ha='right')
|
| 63 |
st.pyplot(fig)
|
| 64 |
|
| 65 |
+
elif page == "์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 3๊ฐ ์ฅ๋ฅด":
|
| 66 |
+
st.title("์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์์ 3๊ฐ ์ฅ๋ฅด")
|
| 67 |
|
| 68 |
# ๋ฐ์ดํฐ ๋ก๋
|
| 69 |
+
file_path = r'C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\6_๋์๋์ถ ํจํด ๋ถ์\์์_3_์ฅ๋ฅด.xlsx'
|
| 70 |
+
df = pd.read_excel(file_path, sheet_name=None)
|
| 71 |
+
df = pd.concat(df.values()) # ๋ชจ๋ ์ํธ ๋ฐ์ดํฐ๋ฅผ ๊ฒฐํฉ
|
| 72 |
|
| 73 |
# ์ฐ๋ น๋ ๋ฌธ์์ด ์ฒ๋ฆฌ
|
| 74 |
df['์ฐ๋ น๋'] = df['์ฐ๋ น'].astype(str)
|
|
|
|
| 82 |
sns.heatmap(genre_age_sex, annot=False, cmap='YlGnBu', linewidths=0.5, ax=ax)
|
| 83 |
ax.set_title('์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์ฅ๋ฅด ์ ํธ๋')
|
| 84 |
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
# ํํธ๋งต ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก
|
| 87 |
+
heat_map_image_path = r'C:\Users\user\Desktop\๋์๊ด_๊ณต๋ชจ์ \์ต์ข
\6_๋์๋์ถ ํจํด ๋ถ์\heat_map_page-0001.jpg'
|
|
|
|
| 88 |
|
| 89 |
+
# ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ํ์
|
| 90 |
+
st.image(heat_map_image_path, caption="์ฐ๋ น๋ ๋ฐ ์ฑ๋ณ์ ๋ฐ๋ฅธ ์ฅ๋ฅด ์ ํธ๋ ํํธ๋งต", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|