Demographic Data Analyzer

This is a Freecodecamp challenge and im struggling a bit, in this part i gotta find the people who are getting paid more than >50K

In the first line i got to group the education backgrounds and count the totals who get more or less than 50K, but in the second cant find the way to slice the unnecessary ones (<=50K) from the df and keep just the one sub row i need

Any enlightenment welcome

df.groupby(df['education'])['salary'].value_counts()
df.loc[(slice(None), '>50K'), :]`

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 (Ecosia android@101.0.4951.41)

Link to the challenge:

Don’t use groupby and don’t use slice. Break it down into 2 steps.

First copy the data into a new dataframe keeping only records with Bachelors or Masters, or Doctorate degrees.

Then use that to make another new dataframe keeping only the records where salary is equal to >50k.

Try to do it in the simplest way possible.

1 Like

Yeah spot on, just followed the steps and came up with this

df.loc[((df['education'] == 'Masters') | (df['education'] == 'Doctorate') | (df['education'] == 'Bachelors')) & (df['salary'] == '>50K')]['salary'].count()
df.loc[((df['education'] != 'Masters') & (df['education'] != 'Doctorate') & (df['education'] != 'Bachelors')) & (df['salary'] == '>50K')]['salary'].count()

Little too horizontal but works! Thank you

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.