Answer to Question #235921 in Python for akshita

Question #235921

Write a program to create a new column in pandas by using values from other columns?

1
Expert's answer
2021-09-11T23:39:32-0400
import pandas as pd
df = pd.DataFrame({'First Name':['Mary', 'John', 'Jennifer', 'Joel'],
                    'Last Name':['Jones', 'Smith', 'Williams', 'Miller'],
                    'Salary':[10000, 20000, 30000, 40000]})


print(df)
#create a new column using using the salary column. Increase the salary by 10%


df['New_Salary'] = df.apply(lambda row: row.Salary + (row.Salary * 0.1), axis = 1)
print(df)

output



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS