Rename Columns - Problem

You are given a DataFrame called students with the following structure:

Column NameType
idint
firstobject
lastobject
ageint

Your task is to rename the columns according to the following mapping:

  • idstudent_id
  • firstfirst_name
  • lastlast_name
  • ageage_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
Rename Columns: Transform Column NamesInput DataFrameidfirstlastage1JohnDoe202AliceSmith19RENAMEcolumnsOutput DataFramestudent_idfirst_namelast_nameage_in_years1JohnDoe202AliceSmith19Data remains identical - only column names are changedResult: More descriptive and standardized column names
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
Asked in
Meta 35 Netflix 28 Google 25
31.5K Views
Medium Frequency
~5 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen