写的python小程序:对班级选举结果进行筛选统计
2013-06-01 13:54
691 查看
源代码和数据链接:源代码: http://download.csdn.net/detail/liyangguang1988/5495209
数据集:http://download.csdn.net/detail/liyangguang1988/5495249
三个班级对学院老师投票选举进行筛选,统计的程序。
程序输入:三个班级的选票文挡。
程序输出:一个过滤掉不满足条件的bad数据集,一个summary文档保存最后选举结果。
三班同学选票的数据格式: 22_23_3_11_19_3_2010210883.txt
一班、二班选票的数据格式:2010210958_1_2_7_16_18_26.txt
排序后的文件内容:(为保护老师隐私,前面的数字对应老师的 ID 号,其对应后面为其的投票数)
![](http://img.blog.csdn.net/20130601134357389)
baddata:
数据集:http://download.csdn.net/detail/liyangguang1988/5495249
三个班级对学院老师投票选举进行筛选,统计的程序。
程序输入:三个班级的选票文挡。
程序输出:一个过滤掉不满足条件的bad数据集,一个summary文档保存最后选举结果。
三班同学选票的数据格式: 22_23_3_11_19_3_2010210883.txt
一班、二班选票的数据格式:2010210958_1_2_7_16_18_26.txt
#!/usr/bin/env python # -*- coding: cp936 -*- #usage: ./1.py dir1 dir2 dir3 ... import os import sys dic = {} for i in range(1,28): dic[i] = 0 ticks = 0 quit = [] teachers = {} teachers['1'] = [str(x) for x in range(1,8)] teachers['2'] = [str(x) for x in range(8,22)] teachers['3'] = [str(x) for x in range(22,28)] def f(dir): print dir+" done" if dir=="三班": files=os.listdir(dir) ticks=len(files) for file in files: tmp=os.path.splitext(file)[0].split('_') flag=0 for i in[0,1]: if tmp[i] not in teachers['3']: flag=1 for i in [2,3,4]: if tmp[i] in teachers['3']: flag=1 if flag: quit.append(file) continue for i in tmp[0:tmp.index("3")]: if i=="0": continue dic[int(i)]+=1 else: files = os.listdir(dir) ticks = len(files) for file in files: tmp = os.path.splitext(file)[0].split('_') if len(tmp) < 7: tmp = os.path.splitext(file)[0].split('-') if len(tmp) < 7: quit.append(file) continue flag = 0 for i in [2,3]: if tmp[i] not in teachers[tmp[1]]: flag = 1 for i in [4,5,6]: if tmp[i] in teachers[tmp[1]]: flag = 1 if flag: quit.append(file) continue for i in tmp[2:]: dic[int(i)] += 1 return ticks for dir in sys.argv[1:]: ticks += f(dir) results = open('summary.txt','w') results.write('Total:{0},Effective:{1}({2:.1f}%),Quit:{3}({4:.1f}%)\n' .format(ticks,ticks-len(quit),(ticks-len(quit))/float(ticks)*100,len(quit),len(quit)/float(ticks)*100) ) for x in sorted(dic.items(), key=lambda x:x[1],reverse=True): results.write('{0:2d}:{1:3d}\n'.format(x[0],x[1])) giveup = open('bad.txt','w') for i in sorted(quit): giveup.write(i+'\n')
排序后的文件内容:(为保护老师隐私,前面的数字对应老师的 ID 号,其对应后面为其的投票数)
baddata:
相关文章推荐
- python语言学习笔记(三)-----模拟投掷三个骰子,对游戏结果进行统计
- 基因数据处理17之使用scala对BWA运行结果进行各阶段程序时间提取和统计求和
- Excel VBA高效办公应用-第六章-客户资料管理-Part3 (对筛选结果进行统计)
- Python对微信好友进行简单统计分析
- 使用Python程序对MySQL进行操作
- 实验 5.2.8-3 对文件的任意部分加锁 1. 用 fcntl()对文件进行锁操作。 2. 完善课件中的示例程序,给出程序运行结果及分析。 给b.txt中的前10个字节加写锁
- python对运行程序进行日志文件记录
- 使用Actor模型对词频统计程序进行多线程优化
- CCS3.3利用profile对程序的运行时间进行统计
- Mysql分表数据通过Python进行汇总统计
- Python进行文本预处理(文本分词,过滤停用词,词频统计,特征选择,文本表示)
- python 实现文章中词汇的频率统计并进行显示(针对英文文章)
- 利用Python进行数据分析(9) pandas基础: 汇总统计和计算
- Python进行主播拉新相关数据统计的脚本
- C-自己写的一个最简单的班级信息统计程序
- Python进行词频统计
- JAVA 调用C 语言程序,并且进行传参收结果等操作
- 每天一个python小程序 004:任一个英文的纯文本文件,统计其中的单词出现的个数
- Python下使用optparse模块实现对多个文件进行统计【二】
- 第一个完整的python程序---统计python3的所有包中,以哪个字母开头的最多?