Question: You want to create a binary variable Salary _ Cat in the data frame df _ Hi , assigning 1 if the player's salary is

You want to create a binary variable Salary_Cat in the data frame df_Hi, assigning 1 if
the player's salary is above the median salary and 0 otherwise. Which of the
following lines of code will do that?
df_Hi['Salary_Cat']= df_Hi['Salary'].apply(lambda x: 1 if x> df_Hi['Salary'].mean()
else 0)
df_Hi['Salary'].apply(lambda x: 1 if x> df_Hi['Salary'].median() else 0)?2
None of the choices works!
df_Hi['Salary_Cat']= df_Hi['Salary'].apply(lambda x: 1 if x >
df_Hi['Salary'].median() else 0)
You want to create a binary variable Salary _ Cat

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!