2884 Modify Columns
Problem Statement
DataFrame employees
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 format is in the following example.
For the whole problem statement, please refer here.
Plans
Load the necessary library (pandas).
Define the function
modifySalaryColumn
that takes in a DataFrame.Inside the function:
Access the salary column.
Double each salary (multiply by 2).
Return the modified DataFrame.
Solution
Explanation
Import Pandas
We start by importing the Pandas library, which provides data structures and operations for manipulating numerical tables and time series.
Define the Function
We define a function
modifySalaryColumn
that takes a single argumentemployees
, which is a DataFrame containing employee data.
Modifying the Salary Column
We access the
salary
column of the DataFrameemployees
using the bracket notation.We multiply each salary by 2 to give the employees a pay rise.
Return the Result
We return the modified DataFrame after doubling the salary of all employees.
Last updated