{"data":{"slug":"github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-category-statistics-330e2d0da0d1","title":"Category Statistics","summary":"Extract and analyze category data to generate distribution statistics and high-resolution visualizations such as bar charts and pie charts.","url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-category-statistics-330e2d0da0d1","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-category-statistics-330e2d0da0d1","markdown_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-category-statistics-330e2d0da0d1.md","download_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-statistics-category-statistics-330e2d0da0d1\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The skill requires a pandas DataFrame with a '\u7c7b\u522b' column for analysis. It generates a statistical summary and visualizations such as bar charts and pie charts.","instructions":"---\nname: category-statistics\ndescription: \"\u63d0\u53d6\u6307\u5b9a\u7c7b\u522b\u5217\u5e76\u7edf\u8ba1\u5404\u7c7b\u522b\u6570\u91cf\u4e0e\u5360\u6bd4\uff0c\u751f\u6210\u9ad8\u5206\u8fa8\u7387\u7684\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u7b49\u7ec4\u5408\u53ef\u89c6\u5316\u62a5\u544a\uff0c\u9002\u7528\u4e8e\u5206\u7c7b\u6570\u636e\u7684\u5206\u5e03\u60c5\u51b5\u5206\u6790\u3002\"\n---\n\n## Skill Steps\n\nStep1 \u63d0\u53d6\u76ee\u6807\u7c7b\u522b\u6570\u636e\uff0c\u6e05\u6d17\u65e0\u6548\u6807\u7b7e\uff0c\u5e76\u7edf\u8ba1\u5404\u7c7b\u522b\u6570\u91cf\u4e0e\u5360\u6bd4\u3002\n```python\nimport pandas as pd\n\ndef calculate_distribution(data, target_col='\u7c7b\u522b'):\n    # \u68c0\u67e5\u76ee\u6807\u5217\u662f\u5426\u5b58\u5728\n    if target_col not in data.columns:\n        raise ValueError(f'\u672a\u627e\u5230\u6307\u5b9a\u7684\u7c7b\u522b\u5b57\u6bb5: {target_col}')\n    \n    # \u63d0\u53d6\u6570\u636e\uff0c\u6e05\u6d17\u65e0\u6548\u6807\u7b7e\uff08\u5982'--'\u3001'\u4ee3\u7801'\u7b49\u5360\u4f4d\u7b26\uff09\n    category_data = data[target_col].dropna().replace(['--', '\u4ee3\u7801'], pd.NA).dropna()\n    \n    # \u7edf\u8ba1\u5404\u7c7b\u522b\u6570\u91cf\u5e76\u8ba1\u7b97\u5360\u6bd4\n    counts = category_data.value_counts()\n    proportions = (counts \/ counts.sum()) * 100\n    \n    # \u5b9e\u7528\u6280\u5de7\uff1a\u751f\u6210\u5305\u542b\u603b\u8ba1\u884c\u7684\u7edf\u8ba1\u8868\n    # summary = counts.copy()\n    # summary.loc['\u603b\u8ba1'] = counts.sum()\n    \n    return counts, proportions\n```\n\nStep2 \u751f\u6210\u57fa\u7840\u53ef\u89c6\u5316\uff08\u53cc\u8f74\u56fe\uff1a\u67f1\u72b6\u56fe+\u5360\u6bd4\u66f2\u7ebf\uff09\uff0c\u5e76\u4fdd\u5b58\u4e3a\u9ad8\u5206\u8fa8\u7387\u56fe\u7247\u3002\n```python\nimport matplotlib.pyplot as plt\n\ndef generate_and_save_basic_chart(counts, proportions, title='\u5404\u7c7b\u522b\u6570\u91cf\u5206\u5e03', output_path='category_distribution.png'):\n    # \u8bbe\u7f6e\u4e2d\u6587\u5b57\u4f53\u907f\u514d\u4e71\u7801\n    plt.rcParams['font.sans-serif'] = ['SimHei', 'WenQuanYi Zen Hei', 'Noto Sans CJK JP', 'DejaVu Sans']\n    plt.rcParams['axes.unicode_minus'] = False\n    \n    fig, ax1 = plt.subplots(figsize=(10, 6))\n    \n    # \u7ed8\u5236\u67f1\u72b6\u56fe\n    bars = ax1.bar(counts.index, counts.values, color='skyblue', edgecolor='black')\n    for bar in bars:\n        height = bar.get_height()\n        ax1.text(bar.get_x() + bar.get_width()\/2., height + 0.05, f'{height}', ha='center', va='bottom', fontsize=10)\n    \n    ax1.set_ylabel('\u6570\u91cf', fontsize=12)\n    ax1.set_title(title, fontsize=16, fontweight='bold', pad=20)\n    \n    # \u521b\u5efa\u7b2c\u4e8c\u4e2ay\u8f74\u663e\u793a\u5360\u6bd4\u66f2\u7ebf\n    ax2 = ax1.twinx()\n    ax2.plot(counts.index, proportions.values, color='red', marker='o', linestyle='-', linewidth=2)\n    ax2.set_ylabel('\u5360\u6bd4 (%)', color='red', fontsize=12)\n    ax2.tick_params(axis='y', labelcolor='red')\n    \n    plt.xticks(rotation=45)\n    plt.tight_layout()\n    \n    # \u4fdd\u5b58\u9ad8\u5206\u8fa8\u7387\u56fe\u8868\u5e76\u4f7f\u7528 plt.close() \u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\n    fig.savefig(output_path, dpi=300, bbox_inches='tight')\n    plt.close(fig)\n    \n    return output_path\n```\n\nStep3 \u751f\u6210\u591a\u56fe\u7ec4\u5408\u62a5\u544a\uff08\u997c\u56fe+\u67f1\u72b6\u56fe\uff0c\u4ee5\u53ca\u5e26\u5206\u7c7b\u6620\u5c04\u7684\u6c34\u5e73\u67f1\u72b6\u56fe\uff09\uff0c\u7528\u4e8e\u591a\u7ef4\u5ea6\u5c55\u793a\u3002\n```python\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Patch\n\ndef generate_comprehensive_report(counts, proportions, output_dir='.\/'):\n    plt.rcParams['font.sans-serif'] = ['SimHei', 'WenQuanYi Zen Hei', 'Noto Sans CJK JP', 'DejaVu Sans']\n    plt.rcParams['axes.unicode_minus'] = False\n    \n    # --- 1. \u997c\u56fe\u4e0e\u67f1\u72b6\u56fe\u7ec4\u5408 ---\n    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))\n    \n    # \u997c\u56fe\n    colors = ['#ff9999', '#66b3ff', '#99ff99', '#ffcc99']\n    explode = [0.05] * len(counts) if len(counts) > 0 else None\n    wedges, texts, autotexts = ax1.pie(counts.values, labels=counts.index, autopct='%1.1f%%',\n                                       colors=colors[:len(counts)], explode=explode, shadow=True, startangle=90)\n    ax1.set_title('\u5404\u7c7b\u522b\u6bd4\u4f8b\u5206\u5e03', fontsize=14, fontweight='bold')\n    for autotext in autotexts:\n        autotext.set_color('white')\n        autotext.set_fontweight('bold')\n    \n    # \u67f1\u72b6\u56fe\n    bars = ax2.bar(range(len(counts)), counts.values, color=colors[:len(counts)], alpha=0.8, edgecolor='black')\n    ax2.set_title('\u5404\u7c7b\u522b\u6570\u91cf', fontsize=14, fontweight='bold')\n    ax2.set_xticks(range(len(counts)))\n    ax2.set_xticklabels(counts.index, rotation=45, ha='right')\n    \n    for i, bar in enumerate(bars):\n        height = bar.get_height()\n        ax2.text(bar.get_x() + bar.get_width()\/2., height + 0.5, f'{int(height)}\\n({proportions.iloc[i]:.1f}%)',\n                 ha='center', va='bottom', fontweight='bold')\n    \n    plt.tight_layout()\n    pie_bar_path = f'{output_dir}category_pie_bar.png'\n    plt.savefig(pie_bar_path, dpi=300, bbox_inches='tight')\n    plt.close(fig)\n    \n    # --- 2. \u6c34\u5e73\u67f1\u72b6\u56fe (\u5e26\u5206\u7c7b\u6620\u5c04\u51fd\u6570\u9aa8\u67b6\u4e0e\u989c\u8272\u533a\u5206) ---\n    fig_h, ax_h = plt.subplots(figsize=(12, 8))\n    positions = [f'\u7c7b\u522b{i+1}' for i in range(len(counts))]\n    \n    # \u5206\u7c7b\u6620\u5c04\u793a\u4f8b\uff1a\u6839\u636e\u7c7b\u522b\u540d\u79f0\u5305\u542b\u7684\u5173\u952e\u5b57\u52a8\u6001\u5206\u914d\u989c\u8272\n    bar_colors = ['#66b3ff' if '\u5173\u952e\u5b57A' in str(p) else '#ff9999' for p in counts.index]\n    bars_h = ax_h.barh(positions, counts.values, color=bar_colors, alpha=0.8, edgecolor='black')\n    \n    ax_h.set_title('\u5404\u7c7b\u522b\u5206\u5e03\u8be6\u60c5', fontsize=16, fontweight='bold', pad=20)\n    \n    for i, (bar, label) in enumerate(zip(bars_h, counts.index)):\n        width = bar.get_width()\n        # \u52a8\u6001\u6807\u7b7e\u793a\u4f8b\uff1a\u63d0\u53d6\u7279\u5b9a\u5c5e\u6027\n        tag = '\u7c7b\u578bA' if '\u5173\u952e\u5b57A' in str(label) else '\u5176\u4ed6'\n        ax_h.text(width + 0.3, bar.get_y() + bar.get_height()\/2, f'{int(width)} ({tag})',\n                  ha='left', va='center', fontsize=10)\n    \n    # \u81ea\u5b9a\u4e49\u56fe\u4f8b\n    legend_elements = [Patch(facecolor='#66b3ff', label='\u7c7b\u578bA\u7ec4'), Patch(facecolor='#ff9999', label='\u5176\u4ed6\u7ec4')]\n    ax_h.legend(handles=legend_elements, loc='lower right')\n    ax_h.grid(axis='x', alpha=0.3)\n    \n    plt.tight_layout()\n    hbar_path = f'{output_dir}category_hbar.png'\n    plt.savefig(hbar_path, dpi=300, bbox_inches='tight')\n    plt.close(fig_h)\n    \n    return [pie_bar_path, hbar_path]\n```\n","use_cases":["Analyzing customer feedback categories to identify dominant themes.","Evaluating product category performance for sales insights."],"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\/category-statistics\/SKILL.md","source_commit":"07e7ff8c4bdfd7b79e7402fe94af59d2a5a9749b","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T08:28:52.000000Z","updated_at":"2026-11-16T05:16:30.000000Z","seo_title":"Category Statistics: Distribution Analysis and Visualization","seo_description":"Extract category data, calculate distribution statistics, and generate high-resolution visualizations for classification analysis.","seo_keywords":["category distribution analysis","data visualization for categories","category statistics report","classification data analysis"]}}