Create intermediate Works with: Any AI

Merge CSV Files With Different Column Names Using a Mapping

Table output

Combine CSV exports with different column names into one tidy table using a mapping dictionary, type fixes and a report of unmapped columns.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratingsโ€ฆ

Write a Python (pandas) script that combines CSV files whose column names differ, such as exports from different tools. Folder: [FOLDER_PATH]. Systems or sources the files come from: [SOURCE_SYSTEMS]. For each source, its column names and what they mean: [COLUMN_MEANINGS]. The final column names and types I want: [TARGET_COLUMNS_AND_TYPES]. Date formats seen: [DATE_FORMATS]. Number formats seen (commas, currency symbols): [NUMBER_FORMATS].

Design the script with:

1. A mapping dictionary at the top (source name to target name), one block per source, which I can edit.

2. A function that detects which source a file belongs to by its header, with a clear error if nothing matches.

3. Cleaning functions for dates, numbers, text trimming and empty strings, each applied only to the columns I list.

4. A final check that prints unmapped columns, rows with failed conversions and the count of each (do not silently drop rows; write them to a separate rejects file).

5. A summary with the arithmetic: rows in per file, rows rejected, rows out.

After the code, add a one-page explanation of the mapping approach for a beginner, and a testing plan using two tiny invented sample files that you provide as text I can save.

Never modify the originals, and never overwrite output without a flag. Say clearly which assumptions you made about my data. Do not claim to have executed the code. If my column meanings are unclear, ask me before writing the mapping.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

Related prompts