2884. Modify Columns
DataFrame employees
Column Name | Type |
---|---|
name | object |
salary | int |
Instructions
- 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 format is in the following example.
Example
Input:
DataFrame employees
name | salary |
---|---|
Jack | 19666 |
Piper | 74754 |
Mia | 62509 |
Ulysses | 54866 |
Output:
name | salary |
---|---|
Jack | 39332 |
Piper | 149508 |
Mia | 125018 |
Ulysses | 109732 |
Explanation:
Every salary has been doubled.
Submissions
python
import pandas as pd
def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
employees['salary'] = employees['salary'] * 2
return employees
Explanation
Python (Pandas)
Submitted by @noeyislearning
import pandas as pd
: Import the pandas library to work with DataFrames.def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
: Define a function calledmodifySalaryColumn
that takes a DataFrameemployees
as input and returns a DataFrame.employees['salary'] = employees['salary'] * 2
: Modify thesalary
column by multiplying each salary by 2.return employees
: Return the modified DataFrameemployees
.