抱歉,我没有足够的变量信息
female
.
试试这个:
def decade_total_count(decade, name):
"""
sums up the number of births of the given
female baby `name` in a 10-year period
Parameters:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
decade ... starting year of the decade
name ... female name
... str
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
count = 0
for i in range(decade, decade+10):
try:
yearly = females[(females['name']==name) & (females['year']==i)]['births'].item()
except ValueError:
continue
count = count + yearly
return count
如果
ValueError
被提出,只需捕捉它并运行下一个迭代。