1.统计出生率

数据下载地址:https://github.com/fivethirtyeight/data/tree/master/births

U.S. births data
The raw data behind the story Some People Are Too Superstitious To Have A Baby On Friday The 13th
File:
US_births_1994-2003_CDC_NCHS.csv
contains U.S. births data for the years 1994 to 2003, as provided by the Centers for Disease Control and Prevention's National Center for Health Statistics

目的:统计每年/月/日出生人数,返回dictionary
过程很简单,主要目的在于体会Python语言的简单特性:

str_list=open('US_births_1994-2003_CDC_NCHS.csv').read().split('\n')

def calc_counts(data,col):
    births_per_col={}
    for line in data:
        if line[col] not in births_per_col:
            births_per_col[line[col]]=line[4]
        else:
            births_per_col[line[col]]+=line[4]
    return births_per_col

cdc_year_births=calc_counts(cdc_list,0)
print('births per year:',cdc_year_births) 
cdc_month_births=calc_counts(cdc_list,1)
print('births per month:',cdc_month_births) 
cdc_dom_births=calc_counts(cdc_list,2)
print('births per day of month:',cdc_dom_births) 
cdc_dow_births=calc_counts(cdc_list,3)
print('births per day of week:',cdc_dow_births) 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,941评论 0 23
  • 以上均拍摄于郑大校园 手机拍摄,如有不清,请谅解,谢谢*^_^* 图片版权归本人所有,图片授权于简书用于设置为ap...
    风与阅读 207评论 0 0
  • 欢迎关注微信公众号“小池琪看日剧”!这是一个日剧迷写给日剧迷的梦想日记。 今天写点日影日剧以外的,和你一起聊聊看书...
    小池琪阅读 702评论 1 0
  • 总有一些事情难以忘记,比如在吃炸鸡或鸡肉卷的选择上,我第一次面对了。是的很难忘,但到最后也是决定了,那就是把这个问...
    d03882ec37e9阅读 86评论 0 0