excel-smart-analysis-and-cleaning
Installation
SKILL.md
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)