Update app.py
Browse files
app.py
CHANGED
|
@@ -635,6 +635,9 @@ def process_upload(file):
|
|
| 635 |
else:
|
| 636 |
return None, f"不支持的文件類型: {file_type}。請上傳CSV或Excel文件。"
|
| 637 |
|
|
|
|
|
|
|
|
|
|
| 638 |
return df, f"成功載入數據,共{len(df)}行,{len(df.columns)}列"
|
| 639 |
|
| 640 |
except Exception as e:
|
|
@@ -658,11 +661,14 @@ def parse_data(csv_data):
|
|
| 658 |
# 默認使用逗號
|
| 659 |
df = pd.read_csv(io.StringIO(csv_data))
|
| 660 |
|
|
|
|
|
|
|
|
|
|
| 661 |
return df, f"成功解析數據,共{len(df)}行,{len(df.columns)}列"
|
| 662 |
|
| 663 |
except Exception as e:
|
| 664 |
return None, f"解析數據時出錯: {str(e)}"
|
| 665 |
-
|
| 666 |
def export_data(df, format_type):
|
| 667 |
"""導出數據為各種格式"""
|
| 668 |
if df is None or df.empty:
|
|
@@ -795,7 +801,7 @@ with gr.Blocks(title="進階數據可視化工具") as demo:
|
|
| 795 |
agg_function = gr.Dropdown(
|
| 796 |
AGGREGATION_FUNCTIONS,
|
| 797 |
label="聚合函數",
|
| 798 |
-
value="
|
| 799 |
info="選擇如何彙總數據"
|
| 800 |
)
|
| 801 |
|
|
|
|
| 635 |
else:
|
| 636 |
return None, f"不支持的文件類型: {file_type}。請上傳CSV或Excel文件。"
|
| 637 |
|
| 638 |
+
# 添加計數列
|
| 639 |
+
df['計數'] = 1
|
| 640 |
+
|
| 641 |
return df, f"成功載入數據,共{len(df)}行,{len(df.columns)}列"
|
| 642 |
|
| 643 |
except Exception as e:
|
|
|
|
| 661 |
# 默認使用逗號
|
| 662 |
df = pd.read_csv(io.StringIO(csv_data))
|
| 663 |
|
| 664 |
+
# 添加計數列
|
| 665 |
+
df['計數'] = 1
|
| 666 |
+
|
| 667 |
return df, f"成功解析數據,共{len(df)}行,{len(df.columns)}列"
|
| 668 |
|
| 669 |
except Exception as e:
|
| 670 |
return None, f"解析數據時出錯: {str(e)}"
|
| 671 |
+
|
| 672 |
def export_data(df, format_type):
|
| 673 |
"""導出數據為各種格式"""
|
| 674 |
if df is None or df.empty:
|
|
|
|
| 801 |
agg_function = gr.Dropdown(
|
| 802 |
AGGREGATION_FUNCTIONS,
|
| 803 |
label="聚合函數",
|
| 804 |
+
value="計數",
|
| 805 |
info="選擇如何彙總數據"
|
| 806 |
)
|
| 807 |
|