EasyNo. 2881

Create a New Column — LeetCode 2881 Python Solution

Topics
Pandas
Reading time
2 min

Table schema

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

Example

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

Python solution

PythonSolution
import pandas as pd


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

Complexity

Time
O(1)
Space · auxiliary
O(1)

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.

Free to download. Check it runs on your machine, then pick a plan.