Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, Please what is the code to filter out the No Gender value in the column Gender I have the code below but it doesn't

Hi,

Please what is the code to filter out the "No Gender" value in the column "Gender"

I have the code below but it doesn't seem to be working,

group = df.groupby(['Gender']).filter(lambda x: x['Gender'].isin(['Male','Female']))

I'm getting the code error message below;

TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_46972\2247951647.py in  ----> 1 group = df.groupby(['Gender']).filter(lambda x: x['Gender'].isin(['Male','Female'])) C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\groupby\generic.py in filter(self, func, dropna, *args, **kwargs) 1315 else: 1316 # non scalars aren't allowed -> 1317 raise TypeError( 1318 f"filter function returned a {type(res).__name__}, " 1319 "but expected a scalar bool" TypeError: filter function returned a Series, but expected a scalar bool

Thank you.

image text in transcribed

In [60]: M \#5 print the names of male and female employees with highest and lowest salaries. In [78]: group =df. groupby ([ geGender ]) In [79]: M highest_salary = group.apply (lambda x: x.nlargest (1, 'Salary' ) ) In [80]: M print(highest_salary[['First Name', 'Gender', 'Salary']]) GenderFemaleMaleNoGender644981746FirstNameKatherineJamesRussellGenderFemaleMaleNoGenderSalary149908148985149456 In [81]: M lowest_salary = group.apply(lambda x: x.nsmallest(1, 'Salary' )) In [82]: M print(lowest_salary[['First Name', 'Gender', 'Salary']]) GenderFemaleMaleNoGender650576417FirstNameCynthiaMichaelSarahGenderFemaleMaleNoGenderSalary353813501337748 In [83]: M group =df. groupby ([ 'Gender' ])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions