{"data":{"slug":"github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-grouped-statistics-208202abde99","title":"Multi-Sheet Excel Data Merging and Top N Analysis","summary":"Perform row count statistics, data merging, and forward filling on multi-sheet Excel files to generate a beautified analysis report, supporting Top N filtering and format.","url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-grouped-statistics-208202abde99","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-grouped-statistics-208202abde99","markdown_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-grouped-statistics-208202abde99.md","download_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-grouped-statistics-208202abde99\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The process requires a Python environment with pandas and openpyxl installed. The user must provide the file path and sheet names for processing.","instructions":"---\nname: grouped-statistics\ndescription: \"\u5bf9\u591a Sheet \u7684 Excel \u6587\u4ef6\u8fdb\u884c\u884c\u6570\u7edf\u8ba1\u3001\u6570\u636e\u5408\u5e76\u4e0e\u524d\u5411\u586b\u5145\u3002\"\n---\n\n## Skill Steps\n\n> **Note**: This sub-skill covers one step of the Excel analysis workflow. For the full pipeline (file reading, row counting, large-file optimization, export), see the parent workflow SKILL.md.\n\nStep1 \u63d0\u53d6\u5173\u952e\u7ef4\u5ea6\u4e0e\u6307\u6807\u4fe1\u606f\uff0c\u5904\u7406\u5408\u5e76\u5355\u5143\u683c\u7f3a\u5931\u503c\uff0c\u5e76\u8fdb\u884c\u591a\u8868\u4ea4\u53c9\u5206\u6790\u4e0e\u6392\u5e8f\u3002\n```python\nimport pandas as pd\n\n# \u8bbe\u5b9a\u76ee\u6807\u5217\u540d\ngroup_col = '\u884c\u4e1a\u540d\u79f0'\ntarget_val_1 = '\u4f01\u4e1a\u5355\u4f4d\u6570'\ntarget_val_2 = '\u5de5\u4e1a\u603b\u4ea7\u503c'\n\n# \u8bfb\u53d6\u7b2c\u4e00\u4e2a Sheet \u5e76\u6e05\u6d17\ndf1 = pd.read_excel(file_path, sheet_name=sheet_names[0], header=None)\n# \u5047\u8bbe\u6570\u636e\u4ece\u7b2c 21 \u884c\u5f00\u59cb\uff0c\u63d0\u53d6\u7ef4\u5ea6\u5217\u4e0e\u6570\u503c\u5217\ndata_1 = df1.iloc[21:63, [0, 2]].copy()\ndata_1.columns = [group_col, target_val_1]\n\n# \u5904\u7406\u5408\u5e76\u5355\u5143\u683c\uff1a\u524d\u5411\u586b\u5145\u7ef4\u5ea6\u5217\ndata_1[group_col] = data_1[group_col].ffill()\ndata_1[target_val_1] = pd.to_numeric(data_1[target_val_1], errors='coerce')\n\n# \u8bfb\u53d6\u7b2c\u4e8c\u4e2a Sheet \u5e76\u63d0\u53d6\u8865\u5145\u6307\u6807\ndf2 = pd.read_excel(file_path, sheet_name=sheet_names[1], header=None)\ndata_2 = df2.iloc[5:47, [0, 1]].copy()\ndata_2.columns = ['temp_dim', target_val_2]\ndata_2[target_val_2] = pd.to_numeric(data_2[target_val_2], errors='coerce')\n\n# \u4ea4\u53c9\u5206\u6790\uff1a\u57fa\u4e8e\u7d22\u5f15\u6216\u7ef4\u5ea6\u5217\u5408\u5e76\nmerged_df = pd.merge(data_1, data_2.reset_index(), left_index=True, right_index=True, how='inner')\nmerged_df = merged_df[[group_col, target_val_1, target_val_2]].dropna(subset=[target_val_1])\n\n# \u7b5b\u9009 Top N \u7ed3\u679c\ntop5_df = merged_df.nlargest(5, target_val_1).reset_index(drop=True)\ntop5_df.index = top5_df.index + 1\nprint(top5_df)\n```\n\nStep2 \u5bf9\u7b5b\u9009\u51fa\u7684\u5173\u952e\u6570\u636e\u8fdb\u884c\u683c\u5f0f\u5316\u6807\u6ce8\uff08\u5982\u6807\u7ea2\u3001\u8fb9\u6846\u3001\u5bf9\u9f50\uff09\uff0c\u751f\u6210\u7f8e\u5316\u540e\u7684 Excel \u6587\u4ef6\u3002\n```python\nfrom openpyxl import Workbook\nfrom openpyxl.styles import Font, PatternFill, Alignment, Border, Side\n\noutput_path = 'analysis_report.xlsx'\nwb = Workbook()\nws = wb.active\nws.title = 'Top_Analysis'\n\n# \u5b9a\u4e49\u6837\u5f0f\nheader_fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')\nheader_font = Font(bold=True, color='FFFFFF', size=12)\nred_font = Font(color='FF0000', bold=True)\nthin_border = Border(left=Side(style='thin'), right=Side(style='thin'), \n                    top=Side(style='thin'), bottom=Side(style='thin'))\ncenter_align = Alignment(horizontal='center', vertical='center')\n\n# \u5199\u5165\u8868\u5934\nheaders = ['\u6392\u540d'] + list(top5_df.columns)\nfor col, header in enumerate(headers, 1):\n    cell = ws.cell(row=1, column=col, value=header)\n    cell.font = header_font\n    cell.fill = header_fill\n    cell.alignment = center_align\n    cell.border = thin_border\n\n# \u5199\u5165\u6570\u636e\u5e76\u5e94\u7528\u6761\u4ef6\u683c\u5f0f\nfor idx, row in top5_df.iterrows():\n    row_num = idx + 1 # \u8003\u8651\u8868\u5934\n    # \u6392\u540d\u5217\n    ws.cell(row=row_num, column=1, value=idx).border = thin_border\n    # \u7ef4\u5ea6\u5217\n    ws.cell(row=row_num, column=2, value=row[group_col]).border = thin_border\n    # \u6570\u503c\u5217 1\n    cell_v1 = ws.cell(row=row_num, column=3, value=row[target_val_1])\n    cell_v1.border = thin_border\n    cell_v1.number_format = '#,##0'\n    # \u6570\u503c\u5217 2\uff08\u6267\u884c\u6807\u7ea2\u6807\u6ce8\uff09\n    cell_v2 = ws.cell(row=row_num, column=4, value=row[target_val_2])\n    cell_v2.font = red_font\n    cell_v2.border = thin_border\n    cell_v2.number_format = '#,##0.00'\n\n# \u8c03\u6574\u5217\u5bbd\nws.column_dimensions['B'].width = 35\nws.column_dimensions['C'].width = 15\nws.column_dimensions['D'].width = 18\n\nwb.save(output_path)\n```\n\nStep3 \u8f93\u51fa\u6700\u7ec8\u7ed3\u679c\u5e76\u751f\u6210\u4e0b\u8f7d\u94fe\u63a5\u3002\n```python\n# \u786e\u8ba4\u6587\u4ef6\u751f\u6210\u5e76\u63d0\u4f9b\u4e0b\u8f7d\nimport os\nif os.path.exists(output_path):\n    print(f\"\u5206\u6790\u5b8c\u6210\u3002\u7ed3\u679c\u6587\u4ef6\u5df2\u751f\u6210\uff0c\u4e0b\u8f7d\u94fe\u63a5\uff1a{output_path}\")\nelse:\n    print(\"\u6587\u4ef6\u751f\u6210\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u8def\u5f84\u6743\u9650\u3002\")\n```\n","use_cases":["Merge industry data across multiple sheets and perform Top 5 analysis","Handle missing values in merged cells and perform cross-analysis","Generate an Excel analysis report with formatted annotations"],"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-statistics\/grouped-statistics\/SKILL.md","source_commit":"07e7ff8c4bdfd7b79e7402fe94af59d2a5a9749b","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T09:13:25.000000Z","updated_at":"2026-11-16T05:16:30.000000Z","seo_title":"Multi-Sheet Excel Data Merging and Top N Analysis Tool","seo_description":"Perform row count statistics, data merging, and forward filling on multi-sheet Excel files to generate a beautified analysis report, supporting Top N filtering and format","seo_keywords":["Excel Multi-Sheet Data Merging","Top N Analysis Tool","Data Forward Filling","Excel Formatted Output","Data Cross Analysis"]}}