mcpField
D
data-profiler

data-profiler

github.com/majesticlabs-dev数据与数据库5067 次安装7 周前更新
代码仓库

关于 data-profiler

面向数据工程师和分析师的数据集探索技能,可分析列统计、相关性、缺失模式和质量标记,并生成 Markdown、JSON 及可选的 HTML 报告。

主要功能

  1. 01数据集形状与内存分析
  2. 02数值、字符串、日期和类别分析
  3. 03相关性与缺失模式分析
  4. 04自动标记数据质量问题
  5. 05生成 Markdown、JSON 报告及可选 HTML 仪表板

适用场景

  1. 01评估新收到的数据集
  2. 02查找高度相关的列
  3. 03排查缺失值和疑似重复项
  4. 04生成供审核的数据概况报告

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill data-profiler

安装后在 Claude Code 中输入/data-profiler确认已加载。

附带文件scripts/profiling.py

详细介绍

数据剖析器

适用对象: 探索新数据集的数据工程师和分析师。

目标: 生成全面的剖析报告,包括统计数据、相关性和缺失模式。

脚本

从 scripts/profiling.py 执行剖析函数:

from scripts.profiling import (
    profile_dataframe,
    print_profile_summary,
    profile_correlations,
    profile_missing_patterns
)

使用示例

基本剖析
import pandas as pd
from scripts.profiling import profile_dataframe, print_profile_summary

df = pd.read_csv('data.csv')
profile = profile_dataframe(df)
print_profile_summary(profile)

输出:

Shape: 10,000 rows x 15 columns
Memory: 1.23 MB

Column Summary:
  id (int64): 10,000 unique, no nulls
  email (object): 9,847 unique, 1.53% null
  revenue (float64): 3,421 unique, no nulls
  created_at (datetime64[ns]): 365 unique, no nulls
相关性分析
from scripts.profiling import profile_correlations

corr = profile_correlations(df, threshold=0.7)

if corr['high_correlations']:
    print("Highly correlated columns:")
    for c in corr['high_correlations']:
        print(f"  {c['col1']} <-> {c['col2']}: {c['correlation']}")
缺失数据模式
from scripts.profiling import profile_missing_patterns

missing = profile_missing_patterns(df)

for col, stats in missing.items():
    if col != 'co_missing_columns':
        print(f"{col}: {stats['percent']}% missing, max {stats['consecutive_max']} consecutive")

# Check for columns missing together
if 'co_missing_columns' in missing:
    for col1, col2, pct in missing['co_missing_columns']:
        print(f"{col1} and {col2} both missing {pct}% of time")

剖析输出架构

shape: [rows, columns]
memory_mb: float
columns:
  column_name:
    dtype: string
    null_count: int
    null_pct: float
    unique_count: int
    unique_pct: float
    # Numeric columns add:
    min: float
    max: float
    mean: float
    std: float
    median: float
    zeros: int
    negatives: int
    # String columns add:
    min_length: int
    max_length: int
    top_values: {value: count}
    # Datetime columns add:
    min_date: string
    max_date: string
    date_range_days: int

分析维度

数值列
  • 最小值、最大值、范围、均值、中位数、众数
  • 标准差、方差、偏度、峰度
  • 百分位数(5、25、50、75、95)
  • 零值数量、负值数量
  • 异常值检测(IQR 方法)
字符串列
  • 最短/最长/平均长度
  • 模式分析(电子邮件、电话、URL)
  • 出现频率最高的 N 个值
  • 空白问题(前导/尾随)
  • 大小写分布(大写/小写/混合)
  • 空字符串数量
日期时间列
  • 最早/最晚日期、日期范围跨度
  • 序列中的缺失日期
  • 星期分布
  • 小时分布(如果包含时间戳)
分类列
  • 基数、值分布
  • 不平衡率
  • 罕见类别(< 1%)

相关性分析

correlation_matrix = df.select_dtypes(include=[np.number]).corr()

# Highly correlated pairs (> 0.8)
high_corr = []
for i in range(len(correlation_matrix.columns)):
    for j in range(i+1, len(correlation_matrix.columns)):
        if abs(correlation_matrix.iloc[i, j]) > 0.8:
            high_corr.append((
                correlation_matrix.columns[i],
                correlation_matrix.columns[j],
                correlation_matrix.iloc[i, j]
            ))

质量标记

自动标记:

  • 缺失值过多: 缺失值 > 50%
  • 常量列: 只有 1 个唯一值
  • 高基数: 唯一值比例 > 95%(可能是 ID)
  • 疑似重复项: 根据键列判断
  • 数据类型不匹配: 数值以字符串形式存储
  • 未来日期: 日期晚于今天
  • 负值: 通常为正数的列中出现负值

报告章节

执行摘要
  • 数据集形状(行数 x 列数)、内存占用
  • 总体质量评分、严重问题数量
逐列分析
  • 统计表、分布直方图(终端中以 ASCII 格式显示)
  • 高频值(分类数据)、质量警告
关系
  • 相关性热图摘要
  • 潜在外键关系、列依赖关系
建议
  • 建议的数据类型优化
  • 需要调查的列、潜在的数据质量规则

输出格式

  • Markdown 报告: 包含表格的完整详细报告
  • JSON 摘要: 供程序使用的机器可读剖析结果
  • HTML 仪表板: 包含图表的交互式报告(如果可用 ydata-profiling)

依赖项

pandas
numpy

评论

支持 Markdown