con un clic
excel-smart-analysis-and-cleaning
对多 Sheet Excel 进行智能清洗、跨表核对与可视化分析。。
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Menú
对多 Sheet Excel 进行智能清洗、跨表核对与可视化分析。。
Instalar con Codex o Claude Copia este prompt, pégalo en Codex, Claude u otro asistente, y deja que revise la página de la skill y la instale por ti.
Basado en la clasificación ocupacional SOC
Base-layer skill for the SenseNova-Skills project, providing low-level APIs for image generation, recognition (VLM), and text optimization (LLM). This skill does not preprocess inputs; it only calls backend services and returns results. This skill is not user-facing and is intended for upper-layer skills only.
用于用户请求深度研究、系统性研究、竞品分析、方案对比、趋势分析或事实核查时。**遇到以下任一情况就主动使用本 skill,不要自行搜几条就回答**:①用户出现触发词:深度研究 / 深度调研 / 深入研究 / 全面研究 / 系统研究 / 调研 / 调查 / 尽调 / 行业研究 / 市场研究 / 竞品分析 / 政策研究 / 技术研究 / 趋势研究 / 事实核查 / 写一份研究报告 / 调研报告 / 深度报告 / research / deep research;②请求需要跨多来源取证、多维度对比、交叉验证才能给出可靠结论;③用户要求产出报告、白皮书、行业分析或尽调文档;④话题涉及最新政策/市场/产品/价格/法规,需要系统核查。明确要求核验来源的单点事实可走 quick;无核验要求的简单常识问答不使用。模糊或宽泛的"研究/了解一下 X"也优先触发。仅不用于:一句话摘要、已给定单一来源的整理、纯文字润色改写。
用于研究任务的最终呈现形式未知时。比较研究报告、学术论文、表格优先报表、决策备忘录或自定义形式,并用权威标准与真实范例支持推荐。
用于搜索中文社交平台。脚本入口覆盖 B站视频、知乎问答和抖音视频;小红书、微博当前没有脚本入口,只能通过 browser-use / 公开网页兜底。
搜索社区、社媒、新闻热点、百科趋势、开发者生态和技术讨论时使用。
用于学术调研、论文精读、相关工作梳理、百科知识查询和引用链追溯。
| name | excel-smart-analysis-and-cleaning |
| description | 对多 Sheet Excel 进行智能清洗、跨表核对与可视化分析。。 |
Step1 对数据进行深度清洗,包括合并单元格填充(ffill)、正则化文本处理、RGB 颜色分量转换以及异常值识别。
import re
def clean_data(df, target_col):
# 1. 处理合并单元格:向下填充
df[target_col] = df[target_col].ffill()
# 2. 正则清洗:去除数字前缀、特殊字符及首尾空格
def regex_clean(text):
if not isinstance(text, str): return text
text = re.sub(r'^\d+[\.\s\-]+', '', text) # 去除如 "1. " 的前缀
text = re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9]', '', text) # 仅保留中英数
return text.strip()
df[target_col] = df[target_col].apply(regex_clean)
# 3. 数值转换与 RGB 逻辑筛选(示例:筛选黑色/无色值)
# 假设列名为 'Red', 'Green', 'Blue'
rgb_cols = ['Red', 'Green', 'Blue']
for col in rgb_cols:
if col in df.columns:
df[col] = pd.to_numeric(df[col], errors='coerce').fillna(0)
if all(c in df.columns for c in rgb_cols):
black_mask = (df['Red'] == 0) & (df['Green'] == 0) & (df['Blue'] == 0)
df = df[black_mask]
return df
# 遍历所有 sheet 进行清洗
cleaned_dfs = {name: clean_data(df, 'group_col') for name, df in df_dict.items()}
Step2 执行跨表核对与多维度统计分析(如交叉分析、占比统计),并识别关键指标(如问题发现率)。
# 跨表核对示例:核对 Sheet1 与 Sheet2 的数值合计
if 'Sheet1' in cleaned_dfs and 'Sheet2' in cleaned_dfs:
val1 = cleaned_dfs['Sheet1']['amount'].sum()
val2 = cleaned_dfs['Sheet2']['amount'].sum()
print(f"核对结果: Sheet1({val1}) vs Sheet2({val2}), 差异: {val1 - val2}")
# 交叉分析与占比统计
target_df = pd.concat(cleaned_dfs.values(), ignore_index=True)
pivot_table = pd.crosstab(target_df['category_col'], target_df['status_col'])
pivot_table['占比'] = pivot_table.sum(axis=1) / pivot_table.sum().sum()
# 统计特定条件下的最大值(如配合比中的最大用量)
# df.groupby('id_col')['value_col'].max()
Step3 生成可视化图表,配置中英文字体支持,并输出带样式的 Excel 结果及下载链接。
import matplotlib.pyplot as plt
from openpyxl.styles import Font
# 1. 可视化配置
plt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans'] # 支持中文
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(10, 6), dpi=100)
target_df['category_col'].value_counts().plot(kind='bar', color='skyblue')
plt.title("数据分布统计")
plt.tight_layout()
plt.savefig("analysis_chart.png")
# 2. 样式化输出
output_path = "analysis_result.xlsx"
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
target_df.to_excel(writer, index=False, sheet_name='Result')
# 针对特定单元格标红加粗(如数值异常项)
workbook = writer.book
worksheet = writer.sheets['Result']
red_bold_font = Font(color="FF0000", bold=True)
for row in range(2, worksheet.max_row + 1):
# 假设第 3 列是需要检查的数值列
if worksheet.cell(row=row, column=3).value > 100:
worksheet.cell(row=row, column=1).font = red_bold_font
print(f"分析完成,结果已保存至: {output_path}")
# 生成下载链接(环境相关)
# print(f"Download link: [点击下载]({output_path})")