You’re trying to use a different shaped df to mask your df, this is wrong, additionally the way you’re passing the conditions is being used incorrectly. When you compare a column or series in a df with a scalar to produce a boolean mask you should pass just the condition, not use this successively.
def answer_eight(): counties=census_df[census_df['SUMLEV']==50] # this is wrong you're passing the df here multiple times regions = counties[(counties[counties['REGION']==1]) | (counties[counties['REGION']==2])] # here you're doing it again washingtons = regions[regions[regions['COUNTY']].str.startswith("Washington")] # here you're doing here again also grew = washingtons[washingtons[washingtons['POPESTIMATE2015']]>washingtons[washingtons['POPESTIMATES2014']]] return grew[grew['STNAME'],grew['COUNTY']]
you want:
def answer_eight(): counties=census_df[census_df['SUMLEV']==50] regions = counties[(counties['REGION']==1]) | (counties['REGION']==2])] washingtons = regions[regions['COUNTY'].str.startswith("Washington")] grew = washingtons[washingtons['POPESTIMATE2015']>washingtons['POPESTIMATES2014']] return grew[['STNAME','COUNTY']]