Create a New Column — LeetCode 2881 Python Solution

EasyPandas
Problem
#2881
Reading time
2 min

Table schema

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

Example

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

Python solution

Python
import pandas as pd


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

Complexity

MeasureComplexity
TimeO(1)
SpaceO(1) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2881. Create a New Column?
LeetCode 2881. Create a New Column is rated Easy on LeetCode.
What is the time complexity of LeetCode 2881. Create a New Column?
The Python solution on this page runs in O(1).
What is the space complexity of LeetCode 2881. Create a New Column?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 2881. Create a New Column cover?
LeetCode 2881. Create a New Column 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