File size: 4,027 Bytes
f1d604f | 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | import streamlit as st
import pandas as pd
import altair as alt
# ===============================
# 1οΈβ£ λ°μ΄ν° λΆλ¬μ€κΈ°
# ===============================
past_path = '/content/2018-2024.xlsx'
future_path = '/content/μμμμλ_2025μμΈ‘.xlsx'
past_df = pd.read_excel(past_path)
future_df = pd.read_excel(future_path)
past_df['μ'] = past_df['μ'].astype(int)
future_df['μ'] = future_df['μ'].astype(int)
past_df = past_df.rename(columns={'νλ§€λ(kg)': 'y'})
future_df = future_df.rename(columns={'μμμμλ': 'y'})
past_df['y'] = past_df['y'].astype(int)
future_df['y'] = future_df['y'].round().astype(int)
# ===============================
# 2οΈβ£ νμ΄μ§ μ€μ & μ€νμΌ
# ===============================
st.set_page_config(page_title="κ³ΌμΌ μμλ λμ보λ", layout="wide")
st.markdown("""
<style>
/* νμ΄νμ λ μλλ‘ λ΄λ €μ ν€λμ κ²ΉμΉμ§ μκ² */
.main > div:first-child {
padding-top: 50px !important;
}
.title {
font-size: 30px;
font-weight: 700;
margin-top: 25px;
margin-bottom: 20px;
}
</style>
""", unsafe_allow_html=True)
# νμ΄μ§ νμ΄ν
st.markdown("<div class='title'>π κ³ΌμΌ μμλ λμ보λ (κ³Όκ±° + 2025 μμΈ‘)</div>", unsafe_allow_html=True)
# ===============================
# 3οΈβ£ λ°μ΄ν° μ ν
# ===============================
data_type = st.sidebar.radio("π μ¬μ©ν λ°μ΄ν°", ["κ³Όκ±° λ°μ΄ν°", "2025λ
μμΈ‘ λ°μ΄ν°"])
selected_df = past_df if data_type == "κ³Όκ±° λ°μ΄ν°" else future_df
# ===============================
# 4οΈβ£ λ
λ μ ν (2025λ
μμΈ‘μ μ¨κΉ)
# ===============================
if data_type == "κ³Όκ±° λ°μ΄ν°":
available_years = sorted(selected_df['λ
λ'].unique())
selected_years = st.multiselect(
"π
μ‘°νν λ
λ",
available_years,
default=[] # κΈ°λ³Έ μ ν μμ
)
df_filtered = selected_df[selected_df['λ
λ'].isin(selected_years)]
else:
df_filtered = selected_df.copy() # 2025λ
λ§ μ‘΄μ¬ β μλ κ³ μ
# ===============================
# 5οΈβ£ κ³ΌμΌ μ ν (κΈ°λ³Έ μ ν μμ)
# ===============================
fruits = sorted(df_filtered['κ³ΌμΌμ’
λ₯'].unique())
selected_fruits = st.multiselect(
"π νμν κ³ΌμΌ μ ν",
fruits,
default=[] # κΈ°λ³Έ μ ν μμ
)
df_chart = df_filtered[df_filtered['κ³ΌμΌμ’
λ₯'].isin(selected_fruits)]
# ===============================
# 6οΈβ£ κ·Έλν μμ
# ===============================
st.subheader("π μλ³ μμλ κ·Έλν")
if len(df_chart) > 0:
if data_type == "κ³Όκ±° λ°μ΄ν°":
years = sorted(df_chart['λ
λ'].unique())
else:
years = [2025]
for y in years:
st.markdown(f"### π {y}λ
")
df_year = df_chart[df_chart['λ
λ'] == y]
chart = (
alt.Chart(df_year)
.mark_line(point=True)
.encode(
x=alt.X('μ:O', title='μ', axis=alt.Axis(labelAngle=0)),
y=alt.Y('y:Q', title='μμλ'),
color='κ³ΌμΌμ’
λ₯:N',
tooltip=['λ
λ', 'κ³ΌμΌμ’
λ₯', 'μ', 'y']
)
.properties(height=350)
)
st.altair_chart(chart, use_container_width=True)
else:
st.info("κ·Έλνμ νμν κ³ΌμΌμ μ ννμΈμ.")
# ===============================
# 7οΈβ£ ν
μ΄λΈ μμ
# ===============================
st.subheader("π μμΈ λ°μ΄ν°")
selected_fruits_table = st.multiselect(
"π ν
μ΄λΈ νμ κ³ΌμΌ",
fruits,
default=[]
)
df_table = df_filtered[df_filtered['κ³ΌμΌμ’
λ₯'].isin(selected_fruits_table)]
if len(df_table) > 0:
df_show = df_table[['λ
λ', 'μ', 'κ³ΌμΌμ’
λ₯', 'y']].rename(columns={'y': 'μμλ'})
st.dataframe(df_show, use_container_width=True)
else:
st.info("ν
μ΄λΈμ νμν κ³ΌμΌμ μ ννμΈμ.")
|