Skip to content

2884. Modify Columns

DataFrame employees

Column NameType
nameobject
salaryint

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

namesalary
Jack19666
Piper74754
Mia62509
Ulysses54866

Output:

namesalary
Jack39332
Piper149508
Mia125018
Ulysses109732

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 called modifySalaryColumn that takes a DataFrame employees as input and returns a DataFrame.
  • employees['salary'] = employees['salary'] * 2: Modify the salary column by multiplying each salary by 2.
  • return employees: Return the modified DataFrame employees.