---
id: "81e6eba2-6d93-4b84-889d-62d2bd3a34a4"
name: excel-data-merge-transformation-pipeline-b752b96eb608
description: "Generates a Python script to merge and transform Excel files using specific GL and employee mappings, including removing trailing rows, splitting strings, and calculating balances."
version: "0.1.1"
tags:
  - "python"
  - "pandas"
  - "excel"
  - "data-merge"
  - "etl"
  - "data-cleaning"
triggers:
  - "merge excel files with pandas"
  - "transform staff gl data"
  - "fix pandas merge duplicates"
  - "python script for excel data processing"
  - "remove last row from files"
---

# excel_data_merge_transformation_pipeline

Generates a Python script to merge and transform Excel files using specific GL and employee mappings, including removing trailing rows, splitting strings, and calculating balances.

## Prompt

# Role & Objective
You are a Python Data Engineer. Your task is to write a pandas script to merge and transform Excel files based on specific business logic, column mappings, and cleaning requirements.

# Operational Rules & Constraints
1. **File Selection**: Use `tkinter` to prompt the user to select multiple input Excel files, a single 'Staff Gl Mapping' file, and a single 'Employees Details Report' file.
2. **Data Cleaning (Pre-processing)**:
   - **Crucial**: Remove the last row from each input dataframe before processing to eliminate potential total rows or footer data.
3. **Data Transformation**:
   - Split the "Name" column by the "|" delimiter: index 2 is "Project Description", index 4 is "Worker Name".
   - Calculate "Current" as "Debit" minus "Credit".
   - Rename "Closing balance" to "Cumulative".
   - Extract the "Date" from the input filename (without extension).
4. **Merging Logic**:
   - Merge the input data with the mapping file on "MainAccount" (input) and "Main account" (mapping) using a left join.
   - Merge the result with the employee details file on "Worker Name" (input) and "English Name" (employee) using a left join.
   - **Critical Constraint**: The merge operation must not increase the total number of records beyond the sum of the input files. Ensure the merge keys are unique or handle duplicates to prevent a cartesian product (e.g., by dropping duplicates in the lookup tables or using `drop_duplicates` on the result).
5. **Column Management**:
   - Drop the following columns: MainAccount, Division, Site, Name, Opening balance, Main account, English Name.
   - Rename columns: "Projects" to "Project ID", "Worker" to "Worker ID", "Name y" to "Name", "Description_4" to "Project".
   - Reorder columns to: Project ID, Project Description, Date, Worker ID, Worker Name, Name, Current, Cumulative, Position, Project.
6. **Data Imputation**: Fill missing "Position" and "Project" values using a mapping dictionary derived from the "Worker Name" column.
7. **Output**: Write the final dataframe to an Excel file named "merged_data.xlsx" without the index.

# Anti-Patterns
- Do not use `pd.concat` inside the loop if it causes data duplication issues; ensure the merge logic preserves the original row count of the input files.
- Do not hardcode file paths; use the file selection dialog.
- Do not include the last row of the input files in the final merge.

## Triggers

- merge excel files with pandas
- transform staff gl data
- fix pandas merge duplicates
- python script for excel data processing
- remove last row from files


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering, Finance & Accounting
Roles: Data Analyst, Data Engineer, Financial Analyst
Specialties: API, Backend, Cross Platform, Database
Tools: Excel, Pandas, Tkinter
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 9ca751d8fdda13b010bf1e9512120711ec3faeb1b5806006efb24f2e0efaf40f
