Modify Columns - Problem
DataFrame Salary Modification
You are working as a data analyst for a company that has decided to give all employees a 100% salary increase due to exceptional performance this year! ๐
Given a DataFrame
Input: A pandas DataFrame with employee names and their current salaries
Output: The same DataFrame with all salaries doubled
Note: This is a DataFrame manipulation problem focusing on column modification operations.
You are working as a data analyst for a company that has decided to give all employees a 100% salary increase due to exceptional performance this year! ๐
Given a DataFrame
employees with columns name and salary, you need to modify the existing salary column by multiplying each employee's current salary by 2.Input: A pandas DataFrame with employee names and their current salaries
Output: The same DataFrame with all salaries doubled
Note: This is a DataFrame manipulation problem focusing on column modification operations.
Input & Output
example_1.py โ Basic Salary Update
$
Input:
employees = pd.DataFrame({'name': ['Alice', 'Bob'], 'salary': [50000, 60000]})
โบ
Output:
pd.DataFrame({'name': ['Alice', 'Bob'], 'salary': [100000, 120000]})
๐ก Note:
Each employee's salary is doubled: Alice goes from $50,000 to $100,000, and Bob goes from $60,000 to $120,000
example_2.py โ Single Employee
$
Input:
employees = pd.DataFrame({'name': ['Charlie'], 'salary': [75000]})
โบ
Output:
pd.DataFrame({'name': ['Charlie'], 'salary': [150000]})
๐ก Note:
With only one employee, Charlie's salary is doubled from $75,000 to $150,000
example_3.py โ Multiple Employees
$
Input:
employees = pd.DataFrame({'name': ['Alice', 'Bob', 'Charlie', 'David'], 'salary': [50000, 60000, 70000, 80000]})
โบ
Output:
pd.DataFrame({'name': ['Alice', 'Bob', 'Charlie', 'David'], 'salary': [100000, 120000, 140000, 160000]})
๐ก Note:
All four employees receive the salary doubling: 50kโ100k, 60kโ120k, 70kโ140k, 80kโ160k
Constraints
- 1 โค number of employees โค 1000
- 1 โค salary โค 106
- All salaries are positive integers
- Employee names are non-empty strings
Visualization
Tap to expand
Understanding the Visualization
1
Access Column
Select the entire salary column from the DataFrame
2
Apply Operation
Use vectorized multiplication to double all values at once
3
Update DataFrame
The modified column replaces the original salary column
4
Return Result
Return the DataFrame with all salaries successfully doubled
Key Takeaway
๐ฏ Key Insight: Vectorized operations in pandas allow us to perform mathematical operations on entire columns simultaneously, making data transformations both fast and intuitive.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code