2884 Modify Columns
Last updated
Last updated
DataFrame employees
Column Name | Type |
---|---|
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.
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.
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 argument employees
, which is a DataFrame containing employee data.
Modifying the Salary Column
We access the salary
column of the DataFrame employees
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.
name
object
salary
int