Modify Columns — LeetCode 2884 Python Solution

EasyPandas
Problem
#2884
Reading time
2 min

Table schema

SQL
DataFrame employees +-------------+--------+ | Column Name | Type | +-------------+--------+ | 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.

Example

SQL
DataFrame employees
+-------------+--------+
| Column Name | Type   |
+-------------+--------+
| name        | object |
| salary      | int    |
+-------------+--------+

Python solution

Python
import pandas as pd


def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame:
    employees['salary'] *= 2
    return employees

Complexity

MeasureComplexity
TimeO(n)
SpaceO(1) to O(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2884. Modify Columns?
LeetCode 2884. Modify Columns is rated Easy on LeetCode.
What topics does LeetCode 2884. Modify Columns cover?
LeetCode 2884. Modify Columns is tagged Pandas on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview