绑定手机号

应国家法规对于账号实名的要求,请您在进行下一步操作前,需要先完成手机绑定 (若绑定失败,请重新登录绑定)。了解更多

不绑定绑定手机号

360官网 | 360商城

推荐论坛版块活动众测商城积分兑换常见问题
import xlrd
import xlsxwriter
import datetime
import matplotlib.pyplot as plt
import math
def get_average(records)
    return sum(records)/len(records)
def get_variance(records)
    average = get_average(records)
    return sum([(x - average) ** 2 for x in records]) / len(records)
def get_standard_deviation(records)
    variance = get_variance(records)
    return math.sqrt(variance)
d = ['data1.xls','data2.xls','data3.xls','data4.xls']
sexs = []
ages = []
error = ['', 'Sex', '工', '1]', '3、', 'Age', 'Occupation', '1、', '户', '1 3', '6+1', 'gr', '###',
          'Report time', 'Time of incidence', '门诊', '科室', 'gr', 'Occupation'
time_format1='/'
time_format2='-'
sums =
man_sum =
woman_sum =
man_age =[]
woman_age =[]
occupationsum = 0
man_occupations_sum =
woman_occupations_sum = 0
occupations_age = [
man_occupation_age = [
woman_occupation_age = [
time = []
professional = []
man_farmer=[]
man_worker=[]
man_retiree=[]
man_teacher=[]
man_fishermen=[]
man_medical_staff=[]
man_worker=[]
man_departing_staff=[]
man_other = []
woman_farmer=[]
woman_worker=[]
woman_retiree=[]
woman_teacher=[]
woman_fishermen=[]
woman_medical_staff=[]
woman_worker=[]
woman_departing_staff=[]
woman_other = []
professional_age =[]
man_professional_age = []
woman_professional_age =[]
result =[]
for j in d:
    data = xlrd.open_workbook(f'{j}')
    table = data.sheets()[0
    nrows = table.nrow
    for i in range(nrows)
        flag = 0
        sex = table.row_values(i)[0]
        age = table.row_values(i)[1]
        occupation = table.row_values(i)[2]
        time_of_incidence = table.row_values(i)[3]
        if not time_of_incidence in error:
            try:
                float(time_of_incidence)
                time.append(datetime.date(1899, 12, 30) + datetime.timedelta(days=time_of_incidence))
            except:
                time.append(time_of_incidence)

        if not occupation in error and not age in error and str(sex) =='1.0'or str(sex)=='1'  :
            professional.append({'sex':1,
                                 'age':float(age),
                                 'pf':occupation})
            man_occupation_age.append(float(age))
            occupationsum+=1
            occupations_age.append(float(age))
            man_occupations_sum+=1
        if not occupation in error and  not age in error and str(sex) =='2.0'or str(sex)=='2'  :
            professional.append({'sex': 2,
                                 'age': float(age),
                                 'pf': occupation})
            woman_occupation_age.append(float(age))
            occupationsum+=1
            occupations_age.append(float(age))
            woman_occupations_sum+=1
        if not sex in error and  not age in error and str(sex) =='1.0'or str(sex)=='1'  :
            ages.append(float(age))
            man_age.append(float(age))
            man_sum +=1
            sums +=1
        if not sex in error and  not age in error and str(sex)=='2.0' or str(sex)=='1' :
            ages.append(float(age))
            woman_age.append(float(age))
            woman_sum += 1
            sums += 1
        if time_format1 in str(time_of_incidence)  or time_format2 in str(time_of_incidence) :
            flag += 1
        if time_format1 in  str(report_time) or  time_format2 in str(report_time) :
            flag +=1
        if  not sex in error and not age in error  and not occupation in error \
                and not time_of_incidence in error and not report_time in error and flag==2:
            result.append({'sex': sex,
                            'age': age,
                            'occupation': occupation,
                            'time_of_incidence':time_of_incidence,
                            'report_time':report_time})
age = []
man_ages = []
woman_ages =[]
occupations_ages =[]
for i in ages:
    if 0<=float(i)<=150.0:
        age.append(round(i))
for i in man_age:
    if 0<=float(i)<=150.0:
        man_ages.append(round(i))
for i in woman_age:
    if 0<=float(i)<=150.0:
        woman_ages.append(round(i))
for i in occupations_age:
    if 0<=float(i)<=150.0:
        occupations_ages.append(round(i))
for i in range(len(professional)):
    if professional['sex'] ==float(1):
        if professional['pf'] ==float(1):
            man_farmer.append(professional['age'])
        elif professional['pf'] ==float(2):
            man_worker.append(professional['age'])
        elif professional['pf'] ==float(3):
            man_retiree.append(professional['age'])
        elif professional['pf'] ==float(4):
            man_teacher.append(professional['age'])
        elif professional['pf'] ==float(5):
            man_fishermen.append(professional['age'])
        elif professional['pf'] ==float(6):
            man_medical_staff.append(professional['age'])
        elif professional['pf'] ==float(7):
            man_worker.append(professional['age'])
        elif professional['pf'] ==float(8):
            man_departing_staff.append(professional['age'])
        else:
            man_other.append(professional['age'])
    if professional['sex']==float(2):
        if professional['pf'] ==float(1):
            woman_farmer.append(professional['age'])
        elif professional['pf'] ==float(2):
            woman_worker.append(professional['age'])
        elif professional['pf'] ==float(3):
            woman_retiree.append(professional['age'])
        elif professional['pf'] ==float(4):
            woman_teacher.append(professional['age'])
        elif professional['pf'] ==float(5):
            woman_fishermen.append(professional['age'])
        elif professional['pf'] ==float(6):
            woman_medical_staff.append(professional['age'])
        elif professional['pf'] ==float(7):
            woman_worker.append(professional['age'])
        elif professional['pf'] ==float(8):
            woman_departing_staff.append(professional['age'])
        else:
            woman_other.append(professional['age'])
for i in range(len(professional)):
    professional_age.append(professional['age'])
    if professional['sex']==float(1):
        man_professional_age.append(professional['age'])
    if professional['sex']==float(2):
        woman_professional_age.append(professional['age'])
print(f'总人数:{sums}')
print(f'平均年龄值:{get_average(age)}')
print(f'年龄标准差:{get_standard_deviation(age)}')
print(f'男人数:{man_sum}')
print(f'女人数:{woman_sum}')
print(f'男人比例{man_sum/sums}')
print(f'女人比例{woman_sum/sums}')
print(f'男人平均年龄{get_average(man_age)}')
print(f'男人年龄标准差{get_standard_deviation(man_age)}')
print(f'女人平均年龄{get_average(woman_age)}')
print(f'女人年龄标准差{get_standard_deviation(woman_age)}')
print(f'农民{len(man_farmer)+len(woman_farmer)}人数'+
      f',男{len(man_farmer)},女{len(woman_farmer)}'+
      f',男比例{len(man_farmer)/(len(man_farmer)+len(woman_farmer))}'+
      f',女比例{len(woman_farmer)/(len(man_farmer)+len(woman_farmer))}')
print(f'农民平均年龄{get_average(man_farmer+woman_farmer)},'+
      f'男{get_average(man_farmer)}女{get_average(woman_farmer)}')
print(f'农民年龄标准差{get_standard_deviation(man_farmer+woman_farmer)}'+
      f',男{get_standard_deviation(man_farmer)}'+
      f',女{get_standard_deviation(woman_farmer)}')
print(f'工人{len(man_worker)+len(woman_worker)}人数,男{len(man_worker)}'+
      f',女{len(woman_worker)},男比例{len(man_worker)/(len(man_worker)+len(woman_worker))}'+
      f',女比例{len(woman_worker)/(len(man_worker)+len(woman_worker))}')
print(f'工人平均年龄{get_average(man_worker+woman_worker)}'+
      f',男{get_average(man_worker)}女{get_average(woman_worker)}')
print(f'工人年龄标准差{get_standard_deviation(man_worker+woman_worker)}'+
      f',男{get_standard_deviation(man_worker)},女{get_standard_deviation(woman_worker)}')
print(f'退休人员{len(man_retiree)+len(woman_retiree)}人数男{len(man_retiree)}'+
      f',女{len(woman_retiree)},男比例{len(man_retiree)/(len(man_retiree)+len(woman_retiree))}'+
      f',女比例{len(woman_retiree)/(len(man_retiree)+len(woman_retiree))}')
print(f'退休人员平均年龄{get_average(man_retiree + woman_retiree)},'+
      f'男{get_average(man_retiree)}女{get_average(woman_retiree)}')
print(f'退休人员年龄标准差{get_standard_deviation(man_retiree + woman_retiree)},'+
      f'男{get_standard_deviation(man_retiree)},女{get_standard_deviation(woman_retiree)}')
print(f'教师{len(man_teacher)+len(woman_teacher)}人数,男{len(man_teacher)},女{len(woman_teacher)}'+
      f',男比例{len(man_teacher)/(len(man_teacher)+len(woman_teacher))}'+
      f',女比例{len(woman_teacher)/(len(man_teacher)+len(woman_teacher))}')
print(f'教师平均年龄{get_average(man_farmer + woman_farmer)}'+
      f',男{get_average(man_teacher)}女{get_average(woman_teacher)}')
print(f'教师年龄标准差{get_standard_deviation(man_farmer + woman_farmer)}'+
      f',男{get_standard_deviation(man_teacher)},女{get_standard_deviation(woman_teacher)}')
print(f'渔民{len(man_fishermen)+len(woman_fishermen)}人数,男{len(man_fishermen)},'+
      f'女{len(woman_fishermen)},男比例{len(man_fishermen)/(len(man_fishermen)+len(woman_fishermen))}'+
      f',女比例{len(woman_fishermen)/(len(man_fishermen)+len(woman_fishermen))}')
print(f'渔民平均年龄{get_average(man_fishermen + woman_fishermen)}'+
      f',男{get_average(man_fishermen)}女{get_average(woman_fishermen)}')
print(f'渔民年龄标准差{get_standard_deviation(man_fishermen + woman_fishermen)}'+
      f',男{get_standard_deviation(man_fishermen)},女{get_standard_deviation(woman_fishermen)}')
print(f'医务人员{len(man_medical_staff)+len(woman_medical_staff)}人数,男{len(man_medical_staff)},'+
      f'女{len(woman_medical_staff)},男比例{len(man_medical_staff)/(len(man_medical_staff)+len(woman_medical_staff))}'+
      f',女比例{len(woman_medical_staff)/(len(man_medical_staff)+len(woman_medical_staff))}')
print(f'医务人员平均年龄{get_average(man_medical_staff + woman_medical_staff)}'+
      f',男{get_average(man_medical_staff)}女{get_average(woman_medical_staff)}')
print(f'医务人员年龄标准差{get_standard_deviation(man_medical_staff + woman_medical_staff)}'+
      f',男{get_standard_deviation(man_medical_staff)},女{get_standard_deviation(woman_medical_staff)}')
print(f'职工{len(man_worker)+len(woman_worker)}人数,男{len(man_worker)},女{len(woman_worker)}'+
      f',男比例{len(man_worker)/(len(man_worker)+len(woman_worker))}'+
      f',女比例{len(woman_worker)/(len(man_worker)+len(woman_worker))}')
print(f'职工平均年龄{get_average(man_worker + woman_worker)}'+
      f',男{get_average(man_worker)}女{get_average(woman_worker)}')
print(f'职工年龄标准差{get_standard_deviation(man_worker + woman_worker)}'+
      f',男{get_standard_deviation(man_worker)},女{get_standard_deviation(woman_worker)}')
print(f'离退人员{len(man_departing_staff)+len(woman_departing_staff)}人数'+
      f',男{len(man_departing_staff)},女{len(woman_departing_staff)}'+
      f',男比例{len(man_departing_staff)/(len(man_departing_staff)+len(woman_departing_staff))}'+
      f',女比例{len(woman_departing_staff)/(len(man_departing_staff)+len(woman_departing_staff))}')
print(f'离退人员平均年龄{get_average(man_departing_staff + woman_departing_staff)}'+
      f',男{get_average(man_departing_staff)}女{get_average(woman_departing_staff)}')
print(f'离退人员年龄标准差{get_standard_deviation(man_departing_staff + woman_departing_staff)},'+
      f'男{get_standard_deviation(man_departing_staff)},女{get_standard_deviation(woman_departing_staff)}')
print(f'其他{len(man_other)+len(woman_other)}人数,男{len(man_other)},女{len(woman_other)}'+
      f',男比例{len(man_other)/(len(man_other)+len(woman_other))}'+
      f',女比例{len(woman_other)/(len(man_other)+len(woman_other))}')
print(f'其他平均年龄{get_average(man_other+woman_other)}'+
      f',男{get_average(man_other)}女{get_average(woman_other)}')
print(f'其他年龄标准差{get_standard_deviation(man_other+woman_other)}'+
      f',男{get_standard_deviation(man_other)},女{get_standard_deviation(woman_other)}')[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]

共 1 个关于大佬帮忙注释一下 python的回复 最后回复于 2020-6-18 18:03

评论

直达楼层

七喜先生 VIP认证 超级版主 发表于 2020-6-18 18:03 | 显示全部楼层 | 私信
如果朋友在此没有征集到好的回答,建议这位朋友去360问答社区(http://wenda.so.com/)相关分类中征集回答,360问答社区的平台上不但有非常多的热心网友和牛人们能帮助到你!同时有了满意答案后还能帮助到其他不懂这个问题的人!感谢朋友对360问答支持!友情提示,悬赏征集会助于你问题的快速解决!一旦有能解决朋友问题的答案的时候,朋友要记得采纳,这样会换来更多朋友的帮助!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

360fans_V1YmY5 LV1.上等兵

粉丝:0 关注:0 积分:9

精华:0 金币:2 经验:8

最后登录时间:2020-6-18

360商城青铜会员

私信 加好友

最新活动

最新活动

排行榜

热度排行 查看排行
今日 本周 本月 全部
    今日 本周 本月 全部

      内容推荐 热门推荐最新主帖

        关注360粉丝团,了解最新活动,抽锦鲤大奖,还有在线客服小姐姐等你来撩哦~

        快速回复 返回顶部 返回列表