age_from_name.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:agefromname 作者: JasonKessler 项目源码 文件源码
def _get_estimated_counts_all_names(self,
                                        sex,
                                        current_year=datetime.now().year,
                                        minimum_age=0):
        '''
        :param sex: str, m or f for sex.
        :param current_year: int, optional, defaults to current year
        :param minimum_age: int, optional, defaults to 0
        :return: pd.Series, with int indices indicating years of
            birth, and estimated counts of total population with that name and birth year
        '''
        sex = self._check_and_normalize_gender(sex)
        cur_df = (self._year_of_birth_df[
                      self._birth_year_df_mask(current_year=current_year,
                                               first_name=None, minimum_age=minimum_age, sex=sex)
                  ][['first_name', 'year_of_birth', 'count']])
        year_stats = (self._mortality_df[self._mortality_df.as_of_year == current_year]
                      [['year_of_birth', sex + '_prob_alive']])
        cur_df['prob_alive'] = np.interp(cur_df.year_of_birth,
                                         year_stats.year_of_birth,
                                         year_stats[sex + '_prob_alive'])
        cur_df['estimated_count'] = cur_df['prob_alive'] * cur_df['count']
        return cur_df  # .set_index('year_of_birth')['estimated_count']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号