# Multi Sheet Reading And Analysis

用于读取多工作表Excel文件，动态评估数据量以启用Parquet大文件优化，并执行正则清洗、分类汇总、线性拟合及生成带格式的图表与结果文件。

- 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 multi-sheet-reading-and-analysis -g -a claude-code -y`
Codex: `npx skills add OpenSenseNova/SenseNova-Skills --skill multi-sheet-reading-and-analysis -g -a codex -y`
Cursor: `npx skills add OpenSenseNova/SenseNova-Skills --skill multi-sheet-reading-and-analysis -g -a cursor -y`
Gemini CLI: `npx skills add OpenSenseNova/SenseNova-Skills --skill multi-sheet-reading-and-analysis -g -a gemini-cli -y`

## Description

用于读取多工作表Excel文件，动态评估数据量以启用Parquet大文件优化，并执行正则清洗、分类汇总、线性拟合及生成带格式的图表与结果文件。

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

Step1 统计多工作表总行数，并根据数据量级（如≥1万行）动态启用Parquet格式转换以优化大文件读取性能。
```python
import pandas as pd
import os
from openpyxl import load_workbook

file_path = "your_excel_file.xlsx"
xls = pd.ExcelFile(file_path)
sheet_names = xls.sheet_names

# 统计所有sheet的数据行数
total_rows = 0
for sheet in sheet_names:
    wb = load_workbook(file_path, read_only=True, data_only=True)
    ws = wb[sheet]
    max_row = ws.max_row
    data_rows = max_row - 1 if max_row > 0 else 0
    total_rows += data_rows
    wb.close()

print(f"总数据行数: {total_rows}")

# 大文件优化：转换为Parquet格式读取
if total_rows >= 10000:
    df = pd.read_excel(file_path, sheet_name=sheet_names[0])
    parquet_path = '/tmp/temp_data.parquet'
    df.to_parquet(parquet_path, engine='pyarrow')
    df = pd.read_parquet(parquet_path)
else:
    df = pd.read_excel(file_path, sheet_name=sheet_names[0])
```

Step2 使用正则表达式对指定文本列进行数据清洗（例如仅保留中文字符）。
```python
import re

def clean_chinese_text(text):
    if pd.isna(text):
        return text
    s = str(text)
    # 提取所有中文字符
    chinese_chars = re.findall(r'[一-鿿]', s)
    cleaned = ''.join(chinese_chars)
    return cleaned if cleaned != '' else ''

target_col = '目标清洗列' # 替换为实际列名
if target_col in df.columns:
    df[target_col] = df[target_col].apply(clean_chinese_text)
```

Step3 提取关键数据进行多维度分析（分类汇总求极值或双变量线性拟合）。
```python
import numpy as np

# 模式1：分类汇总与极值提取
group_col = '分类列'
value_col = '数值列'
# 示例占位数据提取逻辑
summary = pd.DataFrame({
    group_col: ['类别A', '类别B', '类别C'],
    value_col: [100, 500, 200]
})
max_idx = summary[value_col].idxmax()
max_type = summary.loc[max_idx, group_col]

# 模式2：双变量线性关系分析
x_col = 'X轴列'
y_col = 'Y轴列'
if x_col in df.columns and y_col in df.columns:
    x_data = df[x_col].values
    y_data = df[y_col].values
    # 拟合线性趋势线
    coefficients = np.polyfit(x_data, y_data, 1)
    trend_line = np.poly1d(coefficients)(x_data)
```

The rest: https://github.com/OpenSenseNova/SenseNova-Skills/blob/HEAD/skills/sn-da-excel-workflow/capability/excel-reading/multi-sheet-reading/SKILL.md
