Problem Description
Create a new column named bonus
in the employees
DataFrame that contains the doubled values of the salary
column.
Key Insights
- The
bonus
column is derived directly from thesalary
column by multiplying each salary value by 2. - The operation is straightforward as it involves basic arithmetic on numeric data.
- The new column should maintain the same order as the original DataFrame.
Space and Time Complexity
Time Complexity: O(n), where n is the number of rows in the DataFrame, because we iterate through each salary to compute the bonus.
Space Complexity: O(n), as we are creating a new column that holds the bonus values, which requires additional storage proportional to the number of employees.
Solution
To solve this problem, we will use a DataFrame structure that allows us to manipulate tabular data. The algorithmic approach involves iterating through the salary
column and calculating each bonus
value by multiplying the salary by 2. This will be implemented by adding a new column to the existing DataFrame.