Rename Columns - Problem
You are given a DataFrame called students with the following structure:
| Column Name | Type |
|---|---|
| id | int |
| first | object |
| last | object |
| age | int |
Your task is to rename the columns according to the following mapping:
id→student_idfirst→first_namelast→last_nameage→age_in_years
Return the DataFrame with the renamed columns.
Input & Output
Example 1 — Basic DataFrame
$
Input:
students = [{"id": 1, "first": "John", "last": "Doe", "age": 20}]
›
Output:
[{"student_id": 1, "first_name": "John", "last_name": "Doe", "age_in_years": 20}]
💡 Note:
All columns are renamed: id→student_id, first→first_name, last→last_name, age→age_in_years
Example 2 — Multiple Students
$
Input:
students = [{"id": 1, "first": "Alice", "last": "Smith", "age": 19}, {"id": 2, "first": "Bob", "last": "Jones", "age": 21}]
›
Output:
[{"student_id": 1, "first_name": "Alice", "last_name": "Smith", "age_in_years": 19}, {"student_id": 2, "first_name": "Bob", "last_name": "Jones", "age_in_years": 21}]
💡 Note:
Same column renaming applied to all rows in the DataFrame
Example 3 — Empty DataFrame Structure
$
Input:
students = []
›
Output:
[]
💡 Note:
Empty DataFrame remains empty after column renaming operation
Constraints
- DataFrame contains columns: id, first, last, age
- Column renaming must follow the exact mapping specified
- All data values remain unchanged, only column names are modified
Visualization
Tap to expand
Understanding the Visualization
1
Input DataFrame
Original columns: id, first, last, age
2
Apply Renaming
Map each column to more descriptive name
3
Output DataFrame
New columns: student_id, first_name, last_name, age_in_years
Key Takeaway
🎯 Key Insight: Column renaming is a metadata operation that makes DataFrames more readable without changing the underlying data
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code