{"data":{"slug":"github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-visualization-pie-chart-visualization-824c55f52668","title":"Multi-Sheet Data Categorization and Pie Chart Analysis","summary":"Perform categorization and statistical aggregation on multi-sheet Excel or CSV data, automatically identify key fields, and generate downloadable analysis reports with percentages, numerical values, and beautified pie charts.","url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-visualization-pie-chart-visualization-824c55f52668","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-visualization-pie-chart-visualization-824c55f52668","markdown_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-visualization-pie-chart-visualization-824c55f52668.md","download_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-visualization-pie-chart-visualization-824c55f52668\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The tool requires a valid Excel or CSV file as input and assumes that the first sheet contains the data. It also requires the pandas, matplotlib, and openpyxl libraries to be installed.","instructions":"---\nname: pie-chart-data-analysis\ndescription: \"\u5bf9\u591aSheet Excel\u6216CSV\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u6c47\u603b\u7edf\u8ba1\uff0c\u81ea\u52a8\u8bc6\u522b\u5173\u952e\u5b57\u6bb5\u5e76\u751f\u6210\u5305\u542b\u5360\u6bd4\u3001\u6570\u503c\u53ca\u7f8e\u5316\u997c\u56fe\u7684\u53ef\u4e0b\u8f7d\u5206\u6790\u62a5\u544a\u3002\"\n---\n\nStep1 \u8bfb\u53d6\u6587\u4ef6\u5e76\u7edf\u8ba1\u6240\u6709 Sheet \u7684\u884c\u6570\uff0c\u786e\u8ba4\u6570\u636e\u89c4\u6a21\u4ee5\u51b3\u5b9a\u5904\u7406\u7b56\u7565\u3002\n```python\nimport pandas as pd\n\nfile_path = input_file\ntotal_rows = 0\nsheet_names = []\n\ntry:\n    if file_path.endswith('.xlsx'):\n        excel_file = pd.ExcelFile(file_path)\n        sheet_names = excel_file.sheet_names\n        # \u7edf\u8ba1\u6240\u6709\u5de5\u4f5c\u8868\u603b\u884c\u6570\n        for sheet in sheet_names:\n            df_tmp = pd.read_excel(file_path, sheet_name=sheet)\n            total_rows += len(df_tmp)\n    elif file_path.endswith('.csv'):\n        df = pd.read_csv(file_path)\n        total_rows = len(df)\n    else:\n        raise ValueError(\"\u4e0d\u652f\u6301\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u4ec5\u652f\u6301 .xlsx \u6216 .csv\")\nexcept Exception as e:\n    raise RuntimeError(f\"\u6587\u4ef6\u8bfb\u53d6\u5931\u8d25: {e}\")\n\nis_large_file = total_rows >= 10000\n```\n\nStep2 \u81ea\u52a8\u8bc6\u522b\u5206\u7c7b\u5217\u4e0e\u6570\u503c\u5217\uff0c\u6267\u884c\u6570\u636e\u6e05\u6d17\u4e0e\u683c\u5f0f\u8f6c\u6362\u3002\n```python\nimport re\n\n# \u52a0\u8f7d\u9996\u4e2a\u6709\u6548\u6570\u636e\u96c6\nif file_path.endswith('.xlsx'):\n    df = pd.read_excel(file_path, sheet_name=sheet_names[0])\nelse:\n    df = pd.read_csv(file_path)\n\n# 1. \u8bc6\u522b\u6570\u503c\u76ee\u6807\u5217\uff08\u5982\uff1a\u91d1\u989d\u3001\u652f\u51fa\u3001\u5f97\u5206\u3001\u6570\u91cf\uff09\ntarget_keywords = ['\u91d1\u989d', '\u652f\u51fa', '\u9020\u4ef7', '\u7ecf\u8d39', '\u6570\u91cf', '\u5f97\u5206']\ntarget_cols = [col for col in df.columns if any(k in col for k in target_keywords)]\ntarget_col = target_cols[0] if target_cols else df.select_dtypes(include=['number']).columns[0]\n\n# 2. \u8bc6\u522b\u5206\u7c7b\u5217\uff08\u652f\u6301\u6b63\u5219\u5339\u914d\u4e2d\u6587\u5e8f\u53f7\u6216\u7279\u5b9a\u5206\u7c7b\u6807\u8bc6\uff09\ncategory_pattern = re.compile(r'[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e]+|\u5730\u533a|\u7c7b\u522b|\u7c7b\u578b|\u72b6\u6001')\ncategory_cols = [col for col in df.columns if category_pattern.search(col)]\ncategory_col = category_cols[0] if category_cols else df.select_dtypes(include=['object']).columns[0]\n\n# 3. \u6570\u636e\u6e05\u6d17\uff1a\u5904\u7406\u5408\u5e76\u5355\u5143\u683c\u586b\u5145\u3001\u7f3a\u5931\u503c\u53ca\u7c7b\u578b\u8f6c\u6362\ndf[category_col] = df[category_col].ffill() # \u5904\u7406 Excel \u5408\u5e76\u5355\u5143\u683c\ndf[target_col] = pd.to_numeric(df[target_col], errors='coerce')\nclean_df = df[[category_col, target_col]].dropna()\nclean_df.columns = ['category', 'value']\n```\n\nStep3 \u6267\u884c\u591a\u7ef4\u5ea6\u805a\u5408\u5206\u6790\uff0c\u8ba1\u7b97\u5360\u6bd4\u53ca\u6c47\u603b\u7edf\u8ba1\u3002\n```python\n# \u5206\u7c7b\u6c47\u603b\nsummary_df = clean_df.groupby('category', as_index=False)['value'].sum()\ntotal_val = summary_df['value'].sum()\n\n# \u8ba1\u7b97\u5360\u6bd4\u5e76\u683c\u5f0f\u5316\nsummary_df['percentage'] = (summary_df['value'] \/ total_val * 100).round(2)\nsummary_df = summary_df.sort_values(by='value', ascending=False)\n\n# \u6784\u9020\u603b\u8ba1\u884c\uff08\u53ef\u9009\uff09\ntotal_row = pd.DataFrame([['\u603b\u8ba1', total_val, 100.0]], columns=summary_df.columns)\ndisplay_df = pd.concat([summary_df, total_row], ignore_index=True)\n```\n\nStep4 \u751f\u6210\u7f8e\u5316\u997c\u56fe\u5e76\u5bfc\u51fa\u5305\u542b\u56fe\u8868\u7684 Excel \u62a5\u544a\u3002\n```python\nimport matplotlib.pyplot as plt\nfrom io import BytesIO\nimport base64\nfrom openpyxl.drawing.image import Image\n\n# \u914d\u7f6e\u4e2d\u82f1\u6587\u5b57\u4f53\nplt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']\nplt.rcParams['axes.unicode_minus'] = False\n\nfig, ax = plt.subplots(figsize=(10, 7), dpi=120)\ncolors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD']\n\n# \u7a81\u51fa\u663e\u793a\u6700\u5927\u5360\u6bd4\u9879\nexplode = [0.05 if i == 0 else 0 for i in range(len(summary_df))]\n\nwedges, texts, autotexts = ax.pie(\n    summary_df['value'],\n    labels=summary_df['category'],\n    autopct='%1.1f%%',\n    startangle=140,\n    colors=colors,\n    explode=explode,\n    shadow=True,\n    pctdistance=0.85\n)\n\n# \u6dfb\u52a0\u4e2d\u5fc3\u767d\u5708\uff08\u73af\u5f62\u56fe\u6548\u679c\uff09\ncentre_circle = plt.Circle((0,0), 0.70, fc='white')\nfig.gca().add_artist(centre_circle)\n\nplt.title(f'{target_col} \u5206\u5e03\u5206\u6790', fontsize=15, pad=20)\nax.legend(wedges, summary_df['category'], title=\"\u5206\u7c7b\u660e\u7ec6\", loc=\"center left\", bbox_to_anchor=(1, 0, 0.5, 1))\n\n# \u4fdd\u5b58\u56fe\u8868\u5230\u5185\u5b58\nimg_buffer = BytesIO()\nplt.savefig(img_buffer, format='png', bbox_inches='tight')\nplt.close()\n\n# \u5199\u5165 Excel \u5e76\u5d4c\u5165\u56fe\u8868\noutput_path = 'analysis_report.xlsx'\nwith pd.ExcelWriter(output_path, engine='openpyxl') as writer:\n    display_df.to_excel(writer, sheet_name='\u7edf\u8ba1\u6c47\u603b', index=False)\n    ws = writer.book['\u7edf\u8ba1\u6c47\u603b']\n    img_buffer.seek(0)\n    img = Image(img_buffer)\n    ws.add_image(img, 'E2')\n\n# \u751f\u6210 Base64 \u4e0b\u8f7d\u94fe\u63a5\nwith open(output_path, \"rb\") as f:\n    b64 = base64.b64encode(f.read()).decode()\ndownload_url = f\"data:application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}\"\n\nprint(f\"\u5206\u6790\u5b8c\u6210\u3002\u603b\u884c\u6570: {total_rows}\uff0c\u4e0b\u8f7d\u94fe\u63a5\u5df2\u751f\u6210\u3002\")\n```\n","use_cases":["Perform categorization and aggregation on multiple worksheets of sales data, generating pie charts showing the percentage of sales by product category.","Analyze expenditure data across different regions, generating visual reports with region categorization and amount distribution."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/OpenSenseNova\/SenseNova-Skills\/blob\/07e7ff8c4bdfd7b79e7402fe94af59d2a5a9749b\/skills\/sn-da-excel-workflow\/capability\/excel-data-visualization\/pie-chart-visualization\/SKILL.md","source_commit":"07e7ff8c4bdfd7b79e7402fe94af59d2a5a9749b","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T08:55:45.000000Z","updated_at":"2026-11-16T05:16:30.000000Z","seo_title":"Multi-Sheet Data Categorization and Pie Chart Analysis Tool","seo_description":"Automatically identify categorization and numerical columns in Excel or CSV data, generate analysis reports with percentages, numerical values, and beautified pie charts.","seo_keywords":["Multi-Sheet Data Categorization","Excel Data Pie Chart Analysis","CSV Data Statistics Report","Categorization and Percentage Analysis","Data Visualization Tool"]}}