2881. Create a New Column | LeetCode Using Python (Panda Library)

2881. Create a New Column | LeetCode Using Python (Panda Library)

In this short video, I demonstrate how to efficiently add a bonus column to a DataFrame by doubling the salary values using pandas.

In this video, I solve the LeetCode problem 2881, where we need to add a new ‘bonus ‘column to a DataFrame by doubling the values in the existing ‘salary’ column. Using Python’s pandas library, I walk through the step-by-step process of manipulating the DataFrame to create and populate the new column efficiently.

import pandas as pd

def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame:
    #Write a solution to create a new column name bonus that contains the doubled values of the salary column.
    
    employees['bonus'] = employees['salary'] * 2

    return employees

    #Time and Space complexities are O(n) 

Similar Posts