擅长:python、mysql、java
<p>你试图使用不同形状的df来掩盖你的df,这是错误的,另外,你通过条件的方式被错误地使用。将df中的列或序列与标量进行比较以生成布尔掩码时,应仅传递条件,而不是连续使用。</p>
<pre><code>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']]
</code></pre>
<p>你想要:</p>
<pre><code>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']]
</code></pre>