Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,28 +51,43 @@ st.title("📊 ESG & 董事席次數據分析儀表板")
|
|
51 |
data_option = st.sidebar.radio("📂 選擇數據類型", ["ESG 數據", "董事席次數據"])
|
52 |
|
53 |
if data_option == "ESG 數據" and df_esg is not None:
|
|
|
|
|
|
|
54 |
st.subheader("📌 ESG 數據預覽")
|
55 |
st.write(df_esg.head(10))
|
56 |
|
57 |
elif data_option == "董事席次數據" and df_board is not None:
|
|
|
|
|
|
|
58 |
st.subheader("📌 董事席次數據預覽")
|
59 |
st.write(df_board.head(10))
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# 確保數據包含數值型欄位
|
62 |
-
if '
|
63 |
-
numeric_cols =
|
64 |
if len(numeric_cols) > 0:
|
65 |
col_choice = st.selectbox("選擇要視覺化的數值欄位", numeric_cols)
|
66 |
|
67 |
if st.button("生成圖表"):
|
68 |
# 繪製長條圖
|
69 |
st.subheader("📊 長條圖")
|
70 |
-
fig_bar = px.bar(
|
71 |
title=f"{col_choice} 長條圖", color_discrete_sequence=["#1f77b4"])
|
72 |
st.plotly_chart(fig_bar, use_container_width=True)
|
73 |
|
74 |
# 繪製圓餅圖
|
75 |
st.subheader("🥧 圓餅圖")
|
76 |
-
fig_pie = px.pie(
|
77 |
title=f"{col_choice} 圓餅圖")
|
78 |
st.plotly_chart(fig_pie, use_container_width=True)
|
|
|
|
51 |
data_option = st.sidebar.radio("📂 選擇數據類型", ["ESG 數據", "董事席次數據"])
|
52 |
|
53 |
if data_option == "ESG 數據" and df_esg is not None:
|
54 |
+
st.subheader("📌 ESG 數據總覽")
|
55 |
+
st.write(df_esg.describe())
|
56 |
+
|
57 |
st.subheader("📌 ESG 數據預覽")
|
58 |
st.write(df_esg.head(10))
|
59 |
|
60 |
elif data_option == "董事席次數據" and df_board is not None:
|
61 |
+
st.subheader("📌 董事席次數據總覽")
|
62 |
+
st.write(df_board.describe())
|
63 |
+
|
64 |
st.subheader("📌 董事席次數據預覽")
|
65 |
st.write(df_board.head(10))
|
66 |
|
67 |
+
# 添加數據篩選
|
68 |
+
df = df_esg if data_option == "ESG 數據" else df_board
|
69 |
+
filter_col = st.sidebar.selectbox("選擇要篩選的欄位", df.columns)
|
70 |
+
unique_values = df[filter_col].unique()
|
71 |
+
selected_value = st.sidebar.selectbox("選擇篩選值", unique_values)
|
72 |
+
filtered_df = df[df[filter_col] == selected_value]
|
73 |
+
st.write(filtered_df.head())
|
74 |
+
|
75 |
# 確保數據包含數值型欄位
|
76 |
+
if 'filtered_df' in locals() and filtered_df is not None:
|
77 |
+
numeric_cols = filtered_df.select_dtypes(include=['number']).columns
|
78 |
if len(numeric_cols) > 0:
|
79 |
col_choice = st.selectbox("選擇要視覺化的數值欄位", numeric_cols)
|
80 |
|
81 |
if st.button("生成圖表"):
|
82 |
# 繪製長條圖
|
83 |
st.subheader("📊 長條圖")
|
84 |
+
fig_bar = px.bar(filtered_df.head(10), x=filtered_df.index[:10], y=col_choice,
|
85 |
title=f"{col_choice} 長條圖", color_discrete_sequence=["#1f77b4"])
|
86 |
st.plotly_chart(fig_bar, use_container_width=True)
|
87 |
|
88 |
# 繪製圓餅圖
|
89 |
st.subheader("🥧 圓餅圖")
|
90 |
+
fig_pie = px.pie(filtered_df.head(10), names=filtered_df.index[:10], values=col_choice,
|
91 |
title=f"{col_choice} 圓餅圖")
|
92 |
st.plotly_chart(fig_pie, use_container_width=True)
|
93 |
+
|