扮演顶级Python自动化工程师,按指定结构编写Python代码完成Excel数据统计:从格式1转换为格式2的统计模式,在sheet2中匹配sheet1对应姓名的最早日期,生成新工作簿并保存在源文件同文件夹下;优先使用pandas、样式用openpyxl,代码模块化、带中文注释、可直接运行。

中文版提示词

## 角色
你是一位顶级Python自动化工程师,精通数据处理与Office开发。

## 表格背景
请参考以下结构编写代码。

## 任务清单
请按顺序编写Python代码:

### 任务1:数据转换
- 模式:手动定义新功能。
- 补充:sheet1为格式1,sheet2为格式2。
- 请帮我从格式1转换为格式2的统计模式。
- sheet2需匹配出对应sheet1姓名的最早日期。
- 生成一个新的工作簿,保存在源文件同文件夹下。
- 主要参数:文件位置:C:\Users\林木\Desktop\AI写VBA:一键完成Excel数据统计案例1-10 2026.4.24\11.案例11\案例11.xlsx。

## 要求
1. 优先使用pandas,样式调整使用openpyxl。
2. 代码要求:模块化、带详细中文注释、可直接在PyCharm运行。
3. 提供完整的Python脚本。

英文版提示词

## Role
You are a top-tier Python automation engineer, proficient in data processing and Office development.

## Table Background
Write the code with reference to the following structure.

## Task List
Write Python code in order:

### Task 1: Data transformation
- Mode: manually define the new function.
- Supplement: Sheet1 is Format 1, Sheet2 is Format 2.
- Please convert from Format 1 to the statistical pattern of Format 2.
- Sheet2 needs to match the earliest date for the corresponding name in Sheet1.
- Generate a new workbook and save it in the same folder as the source file.
- Key parameter — file location: C:\Users\林木\Desktop\AI写VBA:一键完成Excel数据统计案例1-10 2026.4.24\11.案例11\案例11.xlsx.

## Requirements
1. Prioritize pandas; use openpyxl for style adjustments.
2. Code requirements: modular, with detailed Chinese comments, runnable directly in PyCharm.
3. Provide the complete Python script.

🛠️ **适用 AI 工具**:Claude、ChatGPT、Cursor、Copilot、DeepSeek、Gemini