Modify Columns - Problem
You have a DataFrame employees with two columns:
| Column Name | Type |
|---|---|
| name | object |
| salary | int |
A company intends to give its employees a pay rise. Write a solution to modify the salary column by multiplying each salary by 2.
The result should be the modified DataFrame with updated salaries.
Input & Output
Example 1 — Basic Employee DataFrame
$
Input:
employees = [{"name": "Alice", "salary": 50000}, {"name": "Bob", "salary": 60000}]
›
Output:
[{"name": "Alice", "salary": 100000}, {"name": "Bob", "salary": 120000}]
💡 Note:
Alice's salary: 50000 × 2 = 100000, Bob's salary: 60000 × 2 = 120000
Example 2 — Single Employee
$
Input:
employees = [{"name": "John", "salary": 75000}]
›
Output:
[{"name": "John", "salary": 150000}]
💡 Note:
John's salary doubled: 75000 × 2 = 150000
Example 3 — Multiple Employees
$
Input:
employees = [{"name": "Emma", "salary": 40000}, {"name": "Mike", "salary": 80000}, {"name": "Sara", "salary": 55000}]
›
Output:
[{"name": "Emma", "salary": 80000}, {"name": "Mike", "salary": 160000}, {"name": "Sara", "salary": 110000}]
💡 Note:
All salaries doubled: Emma 40000→80000, Mike 80000→160000, Sara 55000→110000
Constraints
- 1 ≤ employees.length ≤ 104
- 1 ≤ salary ≤ 106
- name consists of alphanumeric characters and spaces
Visualization
Tap to expand
Understanding the Visualization
1
Input DataFrame
Original employee data with name and salary columns
2
Salary Multiplication
Apply × 2 operation to entire salary column
3
Updated DataFrame
Modified DataFrame with doubled salaries
Key Takeaway
🎯 Key Insight: Use vectorized DataFrame operations to efficiently modify entire columns at once rather than processing rows individually
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code