I was able to solve the question, “What percentage of people with advanced education (Bachelors, Masters, or Doctorate) make more than 50K?”
But my code was very “spelled out” and as ugly as can be. I know the same tactics won’t work for the later problems so can someone help me dry up my code and maybe give me some pandas suggestions and tips? Thank you!
A condition applied to a dataframe creates a series of boolean.
Selection a dataframe with a boolean series will create a series only of the entries with “True”.
You can use len() to determine the length of a series.
len( df[ (df.name == “Bob”) or (df.name == “bob”) ] )
Will give you the number of entries where the name was either “Bob” or “bob”.
It’s quite some lengthy code in the challenge and it’s advised you create the series “higher_education” first and then the sub-series with “rich”.
lol I never even looked at that column. Yeah this makes it a bit nicer.
Personally I like len() because it just gives an int, while .count() creates a series unless applied to a single column - also makes it shorter.
But while we are at improvements to look neat, .isin([array]) makes it REALLY neat: