# Numeric Extraction And Distribution Analysis

从带单位的字符串列中提取数值并清洗，生成包含直方图、饼图、条形图和累积分布图的多维度综合分布可视化图表，用于展示数据的集中趋势与分布特征。

- Repository: https://github.com/OpenSenseNova/SenseNova-Skills (6002 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-29
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add OpenSenseNova/SenseNova-Skills --skill numeric-extraction-and-distribution-analysis -g -a claude-code -y`
Codex: `npx skills add OpenSenseNova/SenseNova-Skills --skill numeric-extraction-and-distribution-analysis -g -a codex -y`
Cursor: `npx skills add OpenSenseNova/SenseNova-Skills --skill numeric-extraction-and-distribution-analysis -g -a cursor -y`
Gemini CLI: `npx skills add OpenSenseNova/SenseNova-Skills --skill numeric-extraction-and-distribution-analysis -g -a gemini-cli -y`

## Description

从带单位的字符串列中提取数值并清洗，生成包含直方图、饼图、条形图和累积分布图的多维度综合分布可视化图表，用于展示数据的集中趋势与分布特征。

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Numeric_Extraction_and_Distribution_Analysis

## Skill Steps

Step1 从原始数据中提取目标列，清理无效和空值数据，并安全地将带单位的字符串转换为数值类型
```python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# 配置中英文字体，避免图表乱码
plt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False

item_col = '项目名称'  # 占位示例：分类或名称列
value_col = '带单位的数值'  # 占位示例：需要提取数值的原始列
numeric_col = '提取数值'
unit_str = 'g'  # 占位示例：需要移除的单位字符串

def extract_numeric_value(val_str):
    """从带单位的字符串中提取数值"""
    if pd.isna(val_str):
        return None
    try:
        # 移除单位并转换为浮点数
        return float(str(val_str).replace(unit_str, '').strip())
    except ValueError:
        return None

# 清理缺失值与异常占位符
df_clean = df.dropna(subset=[item_col, value_col]).copy()
df_clean = df_clean[df_clean[item_col] != '...']

# 应用提取函数并过滤转换失败的行
df_clean[numeric_col] = df_clean[value_col].apply(extract_numeric_value)
df_clean = df_clean.dropna(subset=[numeric_col])
```

Step2 创建基础分布直方图，并添加平均值和中位数的参考线以展示数据的集中趋势
```python
plt.figure(figsize=(12, 8))

# 绘制直方图
plt.hist(df_clean[numeric_col], bins=10, alpha=0.7, color='skyblue', edgecolor='black')

# 计算并添加平均值和中位数参考线
mean_val = df_clean[numeric_col].mean()
median_val = df_clean[numeric_col].median()
plt.axvline(mean_val, color='red', linestyle='--', linewidth=2, label=f'平均值: {mean_val:.2f}')
plt.axvline(median_val, color='green', linestyle='--', linewidth=2, label=f'中位数: {median_val:.2f}')

plt.xlabel(f'{numeric_col}', fontsize=12)
plt.ylabel('频数', fontsize=12)
plt.title(f'{numeric_col}分布直方图', fontsize=14, fontweight='bold')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
```

Step3 生成包含直方图、饼图、条形图和累积分布图的综合分析面板，全面展示数值的分布特征并保存高分辨率图片
```python
# 创建 2x2 子图布局
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(16, 12))

The rest: https://github.com/OpenSenseNova/SenseNova-Skills/blob/HEAD/skills/sn-da-excel-workflow/capability/excel-conditional-formatting/data-bar-formatting/SKILL.md
