Spaces:
Running
Running
File size: 4,722 Bytes
ff27984 68fece7 a63a0bc 68fece7 a63a0bc 68fece7 a63a0bc 68fece7 a63a0bc ff27984 68fece7 |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm, skew
import platform
# ํ๊ธ ํฐํธ ์ค์ (๋ค์ํ OS ํ๊ฒฝ ์ง์)
def set_korean_font():
if platform.system() == 'Windows':
plt.rc('font', family='Malgun Gothic')
elif platform.system() == 'Darwin': # Mac
plt.rc('font', family='AppleGothic')
else: # Linux
# ๋๋๊ณ ๋ ํฐํธ๊ฐ ์ค์น๋์ด ์์ด์ผ ํฉ๋๋ค.
# ํฐ๋ฏธ๋์์ `sudo apt-get install -y fonts-nanum*` ์คํ
try:
plt.rc('font', family='NanumGothic')
except:
st.warning("๋๋๊ณ ๋ ํฐํธ๊ฐ ์ค์น๋์ด ์์ง ์์ ํ๊ธ์ด ๊นจ์ง ์ ์์ต๋๋ค. 'sudo apt-get install -y fonts-nanum*' ๋ช
๋ น์ด๋ก ํฐํธ๋ฅผ ์ค์นํด์ฃผ์ธ์.")
plt.rcParams['axes.unicode_minus'] = False # ๋ง์ด๋์ค ํฐํธ ๊นจ์ง ๋ฐฉ์ง
def analyze_scores(df):
"""๋ฐ์ดํฐํ๋ ์์ ๋ฐ์ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ๋ ํจ์"""
st.subheader("๋ฐ์ดํฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ (์์ 5๊ฐ)")
st.dataframe(df.head())
# ๋ถ์ํ ์ ์ ์ด ์ ํ
score_column = st.selectbox("๋ถ์ํ ์ ์ ์ด(column)์ ์ ํํ์ธ์:", df.columns)
if score_column:
scores = df[score_column].dropna()
if pd.api.types.is_numeric_dtype(scores):
st.subheader(f"'{score_column}' ์ ์ ๋ถํฌ ๋ถ์ ๊ฒฐ๊ณผ")
# 1. ๊ธฐ์ ํต๊ณ๋
st.write("#### ๐ ๊ธฐ์ ํต๊ณ๋")
st.table(scores.describe())
# 2. ๋ถํฌ ์๊ฐํ
st.write("#### ๐จ ์ ์ ๋ถํฌ ์๊ฐํ")
fig, ax = plt.subplots(figsize=(10, 6))
sns.histplot(scores, kde=True, stat='density', label='ํ์ ์ ์ ๋ถํฌ', ax=ax)
mu, std = norm.fit(scores)
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
ax.plot(x, p, 'k', linewidth=2, label='์ ๊ท๋ถํฌ ๊ณก์ ')
ax.set_title(f"'{score_column}' ์ ์ ๋ถํฌ (ํ๊ท : {mu:.2f}, ํ์คํธ์ฐจ: {std:.2f})")
ax.set_xlabel('์ ์'); ax.set_ylabel('๋ฐ๋'); ax.legend()
st.pyplot(fig)
# 3. ์๋(Skewness) ๋ถ์
st.write("#### ๐ ์๋ (Skewness) ๋ถ์")
skewness = skew(scores)
st.metric(label="์๋ (Skewness)", value=f"{skewness:.4f}")
if skewness > 0.5:
st.info("๊ผฌ๋ฆฌ๊ฐ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ธด ๋ถํฌ (Positive Skew): ๋๋ถ๋ถ์ ํ์๋ค์ด ํ๊ท ๋ณด๋ค ๋ฎ์ ์ ์์ ๋ชฐ๋ ค์๊ณ , ์ผ๋ถ ๊ณ ๋์ ์๋ค์ด ํ๊ท ์ ๋์ด๊ณ ์์ต๋๋ค.")
elif skewness < -0.5:
st.info("๊ผฌ๋ฆฌ๊ฐ ์ผ์ชฝ์ผ๋ก ๊ธด ๋ถํฌ (Negative Skew): ๋๋ถ๋ถ์ ํ์๋ค์ด ํ๊ท ๋ณด๋ค ๋์ ์ ์์ ๋ชฐ๋ ค์๊ณ , ์ผ๋ถ ์ ๋์ ์๋ค์ด ํ๊ท ์ ๋ฎ์ถ๊ณ ์์ต๋๋ค.")
else:
st.info("๋์นญ์ ๊ฐ๊น์ด ๋ถํฌ: ์ ์๊ฐ ํ๊ท ์ ์ค์ฌ์ผ๋ก ๋น๊ต์ ๊ณ ๋ฅด๊ฒ ๋ถํฌ๋์ด ์์ต๋๋ค.")
else:
st.error(f"์ค๋ฅ: ์ ํํ์ '{score_column}' ์ด์ ์ซ์ ๋ฐ์ดํฐ๊ฐ ์๋๋๋ค. ์ซ์ ํ์์ ์ด์ ์ ํํด์ฃผ์ธ์.")
def main():
set_korean_font()
st.title("ํ์ ์ ์ ๋ถํฌ ๋ถ์ ๋๊ตฌ ๐")
st.write("CSV ํ์ผ์ ์ง์ ์
๋ก๋ํ๊ฑฐ๋ Google Sheets URL์ ๋ถ์ฌ๋ฃ์ด ํ์ ์ ์ ๋ถํฌ๋ฅผ ๋ถ์ํฉ๋๋ค.")
st.write("---")
st.sidebar.title("๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ")
source_option = st.sidebar.radio("๋ฐ์ดํฐ ์์ค๋ฅผ ์ ํํ์ธ์:", ("Google Sheets URL", "CSV ํ์ผ ์
๋ก๋"))
df = None
if source_option == "Google Sheets URL":
url = st.sidebar.text_input("์น์ ๊ฒ์๋ Google Sheets CSV URL์ ์
๋ ฅํ์ธ์.")
if url:
try:
df = pd.read_csv(url)
except Exception as e:
st.error(f"URL๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}")
st.warning("์ฌ๋ฐ๋ฅธ Google Sheets '์น ๊ฒ์' CSV URL์ธ์ง ํ์ธํด์ฃผ์ธ์.")
elif source_option == "CSV ํ์ผ ์
๋ก๋":
uploaded_file = st.sidebar.file_uploader("CSV ํ์ผ์ ์
๋ก๋ํ์ธ์.", type="csv")
if uploaded_file:
try:
df = pd.read_csv(uploaded_file, encoding='utf-8-sig')
except Exception as e:
st.error(f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}")
if df is not None:
analyze_scores(df)
else:
st.info("์ฌ์ด๋๋ฐ์์ ๋ฐ์ดํฐ ์์ค๋ฅผ ์ ํํ๊ณ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์์ฃผ์ธ์.")
if __name__ == '__main__':
main() |