Rename columns
Rename columns — renameColumns
Rename columns via an old → new mapping.
Use cases
- Normalize messy headers (
amt→amount,Cust ID→customer_id). - Align column names across two datasets before a Join or Union/Concat.
What it does
Only the listed columns change; all others pass through untouched.
Before
| amt | Cust ID | ord_dt |
|---|---|---|
| 120.5 | 1001 | 2024-01-01 |
| 89 | 1002 | 2024-01-02 |
2 rows · 3 cols
Rename columns (amt→amount, Cust ID→customer_id, ord_dt→ordered_at)
After
| amount | customer_id | ordered_at |
|---|---|---|
| 120.5 | 1001 | 2024-01-01 |
| 89 | 1002 | 2024-01-02 |
2 rows · 3 cols
Configuration
| Config key | Type | Required | Description |
|---|---|---|---|
mapping | object | Yes | { "old_name": "new_name" } |
Generated Python code
df_2 = df_1.rename(columns={'amt': 'amount'})
Tips & common mistakes
- Only listed columns change; everything else passes through untouched.
- Renaming to a name that already exists will collide — rename or drop the conflicting column first.