Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,16 +66,17 @@ if st.sidebar.button("載入並分析數據"):
|
|
66 |
st.write(df.describe())
|
67 |
|
68 |
# Automatically select columns for visualization
|
|
|
69 |
numeric_columns = df.select_dtypes(include=['int64', 'float64']).columns
|
70 |
-
|
71 |
-
|
72 |
-
y_column = numeric_columns
|
73 |
|
74 |
# Visualization
|
75 |
st.subheader("資料視覺化")
|
76 |
|
77 |
# Pie Chart
|
78 |
-
fig_pie = px.pie(df, names=
|
79 |
fig_pie.update_layout(
|
80 |
font_family="Taipei Sans TC Beta",
|
81 |
title_font_size=24,
|
@@ -85,7 +86,7 @@ if st.sidebar.button("載入並分析數據"):
|
|
85 |
st.plotly_chart(fig_pie, use_container_width=True)
|
86 |
|
87 |
# Bar Chart
|
88 |
-
fig_bar = px.bar(df, x=
|
89 |
fig_bar.update_layout(
|
90 |
font_family="Taipei Sans TC Beta",
|
91 |
title_font_size=24,
|
@@ -109,4 +110,4 @@ else:
|
|
109 |
|
110 |
# Footer
|
111 |
st.markdown("---")
|
112 |
-
st.markdown("使用 Streamlit 創建 ❤️")
|
|
|
66 |
st.write(df.describe())
|
67 |
|
68 |
# Automatically select columns for visualization
|
69 |
+
company_column = df.columns[0] # Assume the first column is the company name
|
70 |
numeric_columns = df.select_dtypes(include=['int64', 'float64']).columns
|
71 |
+
|
72 |
+
if len(numeric_columns) > 0:
|
73 |
+
y_column = st.sidebar.selectbox("選擇數值欄位", options=numeric_columns)
|
74 |
|
75 |
# Visualization
|
76 |
st.subheader("資料視覺化")
|
77 |
|
78 |
# Pie Chart
|
79 |
+
fig_pie = px.pie(df, names=company_column, values=y_column, title=f"{selected_option} 分佈 (圓餅圖)")
|
80 |
fig_pie.update_layout(
|
81 |
font_family="Taipei Sans TC Beta",
|
82 |
title_font_size=24,
|
|
|
86 |
st.plotly_chart(fig_pie, use_container_width=True)
|
87 |
|
88 |
# Bar Chart
|
89 |
+
fig_bar = px.bar(df, x=company_column, y=y_column, title=f"{selected_option} 比較 (柱狀圖)")
|
90 |
fig_bar.update_layout(
|
91 |
font_family="Taipei Sans TC Beta",
|
92 |
title_font_size=24,
|
|
|
110 |
|
111 |
# Footer
|
112 |
st.markdown("---")
|
113 |
+
st.markdown("使用 Streamlit 創建 ❤️")
|