{"data":{"slug":"github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-cleaning-outlier-detection-088a3b48424c","title":"Outlier Detection and Data Quality Assessment","summary":"Perform comprehensive outlier detection and data quality assessment, using the IQR method to identify outliers and combining skewness and kurtosis analysis to examine data distribution characteristics, suitable for preprocessing stages of non-normal distribution data.","url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-cleaning-outlier-detection-088a3b48424c","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-cleaning-outlier-detection-088a3b48424c","markdown_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-cleaning-outlier-detection-088a3b48424c.md","download_url":"https:\/\/skillshunter.net\/skills\/github-opensensenova-sensenova-skills-skills-sn-da-excel-workflow-capability-excel-data-cleaning-outlier-detection-088a3b48424c\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"The process requires loading a dataset in Excel format (e.g., 'data.xlsx') and setting up the environment with Python libraries such as pandas, matplotlib, and seaborn. The first deliverable is a visual report in PNG format ('outlier_analysis_report.png') that includes boxplots and statistical summaries.","instructions":"---\nname: outlier-detection-and-quality-assessment\ndescription: \"\u6267\u884c\u5168\u9762\u7684\u5f02\u5e38\u503c\u68c0\u6d4b\u4e0e\u6570\u636e\u8d28\u91cf\u8bc4\u4f30\uff0c\u5229\u7528 IQR \u65b9\u6cd5\u8bc6\u522b\u5f02\u5e38\u503c\u5e76\u7ed3\u5408\u504f\u5ea6\u3001\u5cf0\u5ea6\u5206\u6790\u6570\u636e\u5206\u5e03\u7279\u5f81\uff0c\u9002\u7528\u4e8e\u975e\u6b63\u6001\u5206\u5e03\u6570\u636e\u7684\u9884\u5904\u7406\u9636\u6bb5\u3002\"\n---\n\n### Step 1 \u52a0\u8f7d\u6570\u636e\u5e76\u914d\u7f6e\u73af\u5883\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\n\n# \u8bbe\u7f6e\u4e2d\u82f1\u6587\u5b57\u4f53\u4ee5\u652f\u6301\u53ef\u89c6\u5316\u663e\u793a (SimHei \u6216 WenQuanYi)\nplt.rcParams['font.sans-serif'] = ['SimHei', 'WenQuanYi Zen Hei', 'DejaVu Sans']\nplt.rcParams['axes.unicode_minus'] = False\n\n# \u52a0\u8f7d\u6570\u636e\nfile_path = 'data.xlsx'  # \u66ff\u6362\u4e3a\u5b9e\u9645\u6587\u4ef6\u8def\u5f84\ndf = pd.read_excel(file_path)\n\n# \u57fa\u7840\u4fe1\u606f\u68c0\u67e5\nprint(f\"\u6570\u636e\u5f62\u72b6: {df.shape}\")\nprint(f\"\u6570\u636e\u7c7b\u578b:\\n{df.dtypes}\")\nprint(df.head())\n```\n\n### Step 2 \u57fa\u4e8e IQR \u65b9\u6cd5\u8bc6\u522b\u5f02\u5e38\u503c\n```python\n# \u81ea\u52a8\u7b5b\u9009\u6570\u503c\u578b\u5217\u8fdb\u884c\u5206\u6790\ntarget_cols = df.select_dtypes(include=[np.number]).columns.tolist()\noutlier_summary = []\n\nfor col in target_cols:\n    data = df[col].dropna()\n    if data.empty:\n        continue\n        \n    # \u56db\u5206\u4f4d\u8ddd\u8ba1\u7b97 (IQR)\n    Q1 = data.quantile(0.25)\n    Q3 = data.quantile(0.75)\n    IQR = Q3 - Q1\n    lower_bound = Q1 - 1.5 * IQR\n    upper_bound = Q3 + 1.5 * IQR\n    \n    # \u8bc6\u522b\u5f02\u5e38\u503c\n    outliers = data[(data < lower_bound) | (data > upper_bound)]\n    \n    outlier_summary.append({\n        'target_col': col,\n        'outlier_count': len(outliers),\n        'outlier_ratio': f\"{(len(outliers)\/len(data)*100):.2f}%\",\n        'lower_limit': lower_bound,\n        'upper_limit': upper_bound,\n        'sample_values': outliers.values.tolist()[:5]  # \u4fdd\u7559\u524d5\u4e2a\u793a\u4f8b\n    })\n\noutlier_df = pd.DataFrame(outlier_summary)\nprint(\"\\n=== \u5f02\u5e38\u503c\u7edf\u8ba1\u6c47\u603b ===\")\nprint(outlier_df.to_string(index=False))\n```\n\n### Step 3 \u751f\u6210\u591a\u7ef4\u5ea6\u53ef\u89c6\u5316\u7bb1\u7ebf\u56fe\n```python\n# \u914d\u7f6e\u591a\u5b50\u56fe\u5e03\u5c40\nnum_cols = len(target_cols)\ncols_per_row = 3\nrows = (num_cols + cols_per_row - 1) \/\/ cols_per_row\n\nfig, axes = plt.subplots(rows, cols_per_row, figsize=(18, 5 * rows))\nfig.suptitle('\u6570\u636e\u5206\u5e03\u4e0e\u5f02\u5e38\u503c\u68c0\u6d4b\u7bb1\u7ebf\u56fe', fontsize=16, fontweight='bold')\naxes_flat = axes.flatten()\n\n# \u904d\u5386\u7ed8\u5236\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5206\u5e03\nfor i, col in enumerate(target_cols):\n    ax = axes_flat[i]\n    # \u7ed8\u5236\u7bb1\u7ebf\u56fe\u5e76\u7f8e\u5316\n    sns.boxplot(y=df[col].dropna(), ax=ax, color='skyblue', width=0.4,\n                flierprops=dict(marker='o', markerfacecolor='red', markersize=5, alpha=0.5))\n    \n    ax.set_title(f'\u5217: {col}', fontsize=12)\n    ax.grid(True, linestyle='--', alpha=0.6)\n    \n    # \u5d4c\u5165\u5b9e\u65f6\u7edf\u8ba1\u6807\u6ce8\n    stats = df[col].describe()\n    stats_text = f'\u5747\u503c: {stats[\"mean\"]:.2f}\\n\u4e2d\u4f4d\u6570: {stats[\"50%\"]:.2f}\\n\u6807\u51c6\u5dee: {stats[\"std\"]:.2f}'\n    ax.text(0.05, 0.95, stats_text, transform=ax.transAxes, fontsize=9,\n            verticalalignment='top', bbox=dict(boxstyle='round', facecolor='white', alpha=0.8))\n\n# \u9690\u85cf\u591a\u4f59\u7684\u5b50\u56fe\nfor j in range(i + 1, len(axes_flat)):\n    axes_flat[j].axis('off')\n\nplt.tight_layout(rect=[0, 0.03, 1, 0.95])\noutput_path = 'outlier_analysis_report.png'\nplt.savefig(output_path, dpi=300, bbox_inches='tight')\nplt.show()\n```\n\n### Step 4 \u504f\u5ea6\u4e0e\u5cf0\u5ea6\u5206\u6790\u53ca\u8d28\u91cf\u8bc4\u4f30\n```python\n# \u5206\u6790\u5206\u5e03\u5f62\u6001\u4ee5\u8f85\u52a9\u6e05\u6d17\u51b3\u7b56\nprint(\"=== \u6570\u636e\u5206\u5e03\u5f62\u6001\u5206\u6790\u62a5\u544a ===\")\nquality_analysis = []\n\nfor col in target_cols:\n    data = df[col].dropna()\n    skewness = data.skew()\n    kurtosis = data.kurtosis()\n    \n    # \u5224\u5b9a\u5206\u5e03\u7279\u5f81\n    skew_type = \"\u53f3\u504f (Positive)\" if skewness > 0.5 else \"\u5de6\u504f (Negative)\" if skewness < -0.5 else \"\u5bf9\u79f0\"\n    kurt_type = \"\u5c16\u5cf0 (Leptokurtic)\" if kurtosis > 1 else \"\u5e73\u5cf0 (Platykurtic)\" if kurtosis < -1 else \"\u6b63\u6001\u8d8b\u5411\"\n    \n    quality_analysis.append({\n        '\u5b57\u6bb5': col,\n        '\u504f\u5ea6': round(skewness, 3),\n        '\u5cf0\u5ea6': round(kurtosis, 3),\n        '\u5206\u5e03\u5f62\u6001': skew_type,\n        '\u5cf0\u5ea6\u7279\u5f81': kurt_type\n    })\n\nanalysis_df = pd.DataFrame(quality_analysis)\nprint(analysis_df.to_string(index=False))\n\n# \u5bfc\u51fa\u5206\u6790\u7ed3\u679c\n# analysis_df.to_csv('data_quality_report.csv', index=False)\n```\n\n### Step 5 \u5f02\u5e38\u503c\u5904\u7406\u5efa\u8bae\uff08\u9aa8\u67b6\uff09\n```python\ndef handle_outliers(df, col, method='cap'):\n    \"\"\"\n    \u5f02\u5e38\u503c\u5904\u7406\u9aa8\u67b6\u51fd\u6570\n    method: 'cap' (\u76d6\u5e3d\u6cd5), 'drop' (\u5220\u9664), 'none' (\u4fdd\u7559)\n    \"\"\"\n    data = df[col].copy()\n    Q1 = data.quantile(0.25)\n    Q3 = data.quantile(0.75)\n    IQR = Q3 - Q1\n    lower = Q1 - 1.5 * IQR\n    upper = Q3 + 1.5 * IQR\n    \n    if method == 'cap':\n        df[col] = df[col].clip(lower=lower, upper=upper)\n    elif method == 'drop':\n        df = df[(df[col] >= lower) & (df[col] <= upper)]\n    \n    return df\n\n# \u793a\u4f8b\uff1a\u5bf9\u7279\u5b9a\u5217\u5e94\u7528\u76d6\u5e3d\u6cd5\u5904\u7406\n# df = handle_outliers(df, 'target_col', method='cap')\n```\n","use_cases":["Identify outliers in a dataset to improve data quality","Analyze data distribution shape to guide data cleaning strategies","Generate visual reports to assist in data preprocessing decisions"],"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-cleaning\/outlier-detection\/SKILL.md","source_commit":"07e7ff8c4bdfd7b79e7402fe94af59d2a5a9749b","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-15T08:11:59.000000Z","updated_at":"2026-11-16T05:16:30.000000Z","seo_title":"Outlier Detection and Data Quality Assessment Tool","seo_description":"Perform comprehensive outlier detection and data quality assessment, suitable for preprocessing stages of non-normal distribution data.","seo_keywords":["Outlier Detection Tool","Data Quality Assessment","IQR Method Analysis","Skewness and Kurtosis Analysis","Data Preprocessing Tool"]}}