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