Xlsx
by enoch-robinson
Excel 电子表格处理工具包。用于创建和编辑电子表格、数据分析、公式计算、格式化。当需要处理 .xlsx/.csv 文件进行数据操作、报表生成或财务建模时使用此技能。
Skill Details
Repository Files
1 file in this skill directory
name: xlsx description: Excel 电子表格处理工具包。用于创建和编辑电子表格、数据分析、公式计算、格式化。当需要处理 .xlsx/.csv 文件进行数据操作、报表生成或财务建模时使用此技能。
XLSX Processing Guide
库选择
| 任务 | 推荐库 | 用途 |
|---|---|---|
| 数据分析 | pandas | 读写、分析、批量操作 |
| 公式/格式 | openpyxl | 保留公式、样式、图表 |
读取数据 (pandas)
import pandas as pd
# 读取 Excel
df = pd.read_excel('file.xlsx') # 默认第一个 sheet
df = pd.read_excel('file.xlsx', sheet_name='Sheet2')
all_sheets = pd.read_excel('file.xlsx', sheet_name=None) # 所有 sheet
# 基础分析
df.head() # 预览
df.info() # 列信息
df.describe() # 统计摘要
创建 Excel (openpyxl)
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment
wb = Workbook()
sheet = wb.active
# 添加数据
sheet['A1'] = '标题'
sheet['B1'] = 100
sheet.append(['行', '数据', '示例'])
# 添加公式(重要:使用公式而非硬编码值)
sheet['B5'] = '=SUM(B2:B4)'
sheet['C5'] = '=AVERAGE(C2:C4)'
# 格式化
sheet['A1'].font = Font(bold=True, color='FF0000')
sheet['A1'].fill = PatternFill('solid', fgColor='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')
# 列宽
sheet.column_dimensions['A'].width = 20
wb.save('output.xlsx')
编辑现有文件
from openpyxl import load_workbook
wb = load_workbook('existing.xlsx')
sheet = wb.active
# 修改单元格
sheet['A1'] = '新值'
# 插入/删除行列
sheet.insert_rows(2)
sheet.delete_cols(3)
# 新建sheet
new_sheet = wb.create_sheet('NewSheet')
wb.save('modified.xlsx')
关键原则
###✅ 使用公式
# 正确:让Excel 计算
sheet['B10'] = '=SUM(B2:B9)'
# 错误:Python 计算后硬编码
total = sum(values)
sheet['B10'] = total # 不要这样做
金融模型颜色规范
| 颜色 | 用途 |
|---|---|
| 蓝色文字 | 硬编码输入值 |
| 黑色文字 | 公式和计算 |
| 绿色文字 | 跨 sheet 引用 |
| 黄色背景 | 需要关注的假设 |
数据导出
# DataFrame导出
df.to_excel('output.xlsx', index=False)
# 多sheet 导出
with pd.ExcelWriter('output.xlsx') as writer:
df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
注意事项
data_only=True读取计算值,但保存后公式会丢失- 大文件使用
read_only=True或write_only=True - 单元格索引从 1 开始(A1 = row=1, column=1)
Related Skills
Attack Tree Construction
Build comprehensive attack trees to visualize threat paths. Use when mapping attack scenarios, identifying defense gaps, or communicating security risks to stakeholders.
Grafana Dashboards
Create and manage production Grafana dashboards for real-time visualization of system and application metrics. Use when building monitoring dashboards, visualizing metrics, or creating operational observability interfaces.
Matplotlib
Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.
Scientific Visualization
Create publication figures with matplotlib/seaborn/plotly. Multi-panel layouts, error bars, significance markers, colorblind-safe, export PDF/EPS/TIFF, for journal-ready scientific plots.
Seaborn
Statistical visualization. Scatter, box, violin, heatmaps, pair plots, regression, correlation matrices, KDE, faceted plots, for exploratory analysis and publication figures.
Shap
Model interpretability and explainability using SHAP (SHapley Additive exPlanations). Use this skill when explaining machine learning model predictions, computing feature importance, generating SHAP plots (waterfall, beeswarm, bar, scatter, force, heatmap), debugging models, analyzing model bias or fairness, comparing models, or implementing explainable AI. Works with tree-based models (XGBoost, LightGBM, Random Forest), deep learning (TensorFlow, PyTorch), linear models, and any black-box model
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Query Writing
For writing and executing SQL queries - from simple single-table queries to complex multi-table JOINs and aggregations
Pydeseq2
Differential gene expression analysis (Python DESeq2). Identify DE genes from bulk RNA-seq counts, Wald tests, FDR correction, volcano/MA plots, for RNA-seq analysis.
Scientific Visualization
Meta-skill for publication-ready figures. Use when creating journal submission figures requiring multi-panel layouts, significance annotations, error bars, colorblind-safe palettes, and specific journal formatting (Nature, Science, Cell). Orchestrates matplotlib/seaborn/plotly with publication styles. For quick exploration use seaborn or plotly directly.
