zoukankan      html  css  js  c++  java
  • 习题1-3 求怀孕周期平均值

    __author__ = 'dell'
    
    import survey
    
    table = survey.Pregnancies()
    table.ReadRecords()
    print "Number of pregnancies ", len(table.records)

    运行结果:
    D:Python27python.exe F:/sync_code/python/first.py
    Number of pregnancies  13593
    Process finished with exit code 0
    计算活婴的数量:
    __author__ = 'dell'
    
    import survey
    
    table = survey.Pregnancies()
    table.ReadRecords()
    print "Number of pregnancies ", len(table.records)
    
    livebirth = 0
    for record in table.records:
        if record.outcome == 1:
            livebirth += 1
    print 'live birth num is :', livebirth

    运行结果:
    D:Python27python.exe F:/sync_code/python/first.py
    Number of pregnancies  13593
    live birth num is : 9148



    核对网址:
    http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=PREG&section=&subSec=8016&srtLabel=611932
    活婴分为两组,第一胎和其他。计算他们的数量:
    __author__ = 'dell'
    
    import survey
    
    table = survey.Pregnancies()
    table.ReadRecords()
    print "Number of pregnancies ", len(table.records)
    
    firsts = survey.Pregnancies()
    others = survey.Pregnancies()
    
    for p in table.records:
        if p.outcome != 1:
            continue
        if p.birthord == 1:
            firsts.AddRecord(p)
        else:
            others.AddRecord(p)
    
    print 'Num of the first babies :', len(firsts)
    print 'Num of others :', len(others )

    运行结果:
    D:Python27python.exe F:/sync_code/python/first.py
    Number of pregnancies  13593
    Num of the first babies : 4413
    Num of others : 4735


    核对网址:
    http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=PREG&section=&subSec=8016&srtLabel=611933
    第一胎婴儿和其他婴儿的平均怀孕周期(单位 周)
    
    __author__ = 'dell'
    
    import survey
    
    table = survey.Pregnancies()
    table.ReadRecords()
    print "Number of pregnancies ", len(table.records)
    
    firsts = survey.Pregnancies()
    others = survey.Pregnancies()
    
    for p in table.records:
        if p.outcome != 1:
            continue
        if p.birthord == 1:
            firsts.AddRecord(p)
        else:
            others.AddRecord(p)
    
    print 'Num of the first babies :', len(firsts)
    print 'Num of others :', len(others )
    
    a = [r.prglength for r in firsts.records]
    b = [r.prglength for r in others.records]
    
    
    def Mean(v):
        return float(sum(v)) / len(v)
    
    print 'the mean of prglength for first babies :', Mean(a)
    print 'the mean of prglength for other babies :', Mean(b)
    
    
    First babies 38.6009517335
    Others 38.5229144667
    
    the mean of prglength for first babies : 38.6009517335
    the mean of prglength for other babies : 38.5229144667
    Difference in days 0.546260867443 day
    Difference in hours  13.1102608186

    第一胎的平均时间 比 其他时间 大 13 小时
  • 相关阅读:
    linux内核中的subsys_initcall是干什么的?
    linux内核中的MFD子系统
    linux内核中有哪些子系统(框架)呢?
    软件架构师书籍
    求最大公约数和最小公倍数
    写一个函数判断字符串中"{"与"}","["与"]","("与")"匹配,"{"必须在"}"前面,"["必须在"]"前面,"("必须在")"前面,可以嵌套
    请用程序写出冒泡排序算法,并做相应改进使得排序效率更高
    50个必备的实用jQuery代码段+ 可以直接拿来用的15个jQuery代码片段
    js同比例缩放图片
    oracle 10g函数大全--其他函数
  • 原文地址:https://www.cnblogs.com/i80386/p/3228421.html
Copyright © 2011-2022 走看看