Python比较与抽取64位是一款python随机抽取对比查找软件,查找谁没填表、重复填表的同学,随机抽取名单,苦于班级事务繁多,在大学里有一堆的表要填,同时总是有同学没看到消息而不填表,本工具诞生于这样的条件下。
软件说明
根本目的为了知道谁没填表,谁重复填表了。
不仅如此,很多需要平均分配的任务还需要随机抽人(班里分出去了教改班的几个同学和原班级)
需要:python(或嵌入式python)
需要的库:
pandas【核心】(同时因为pandas的原因需要numpy与openpyxl)
os
sys
random
目录架构及解释说明:
__Python比较与抽取.exe:主程序,当然你也可以根据python的传参自行调用,随便你
compare.py:核心文件,主要的运算均在此处
in.xlsx:输入要进行运算的学生姓名
例:
ref.xlsx:参考用的表格
格式如下:
out.xlsx:输出用的表格(均为姓名)
Python源码
注:python因为个人习惯的原因写了一大堆传参……
在作者看来python就应该专注于运算,别的GUI,判断运行环境啥的还是交给aardio(粘合剂)吧
[/font][/size]
[size=4][font=微软雅黑]import os
import random
import sys
import pandas as pd
def Initialize():
ref_t_lack = pd.read_excel(
os.getcwd() + "\\ref.xlsx",
header=None
)
ref_s_lack = set()
for i in range(len(ref_t_lack)):
ref_s_lack.add(ref_t_lack.iloc[i][0])
ref_s_all = ref_s_lack.copy()
for i in ["AAA", "BBB", "CCC", "DDD", "EEE"]: # 此处应为教改班同学的姓名
ref_s_all.add(i)
in_t = pd.read_excel(os.getcwd() + "\\in.xlsx", header=None)
in_s = set()
for i in range(len(in_t)):
in_s.add(in_t.iloc[i][0])
try:
os.remove(os.getcwd() + "\\out.xlsx")
except:
pass
out_t = pd.DataFrame()
return ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t
def filter(mode: int,
ref_s_lack: set,
ref_t_lack: pd.DataFrame,
ref_s_all: set,
in_t: pd.DataFrame,
in_s: set,
out_t: pd.DataFrame,
num_pick: int):
re = in_t.duplicated()
for i in range(len(re)):
temp = re.iloc[i]
if(temp == True):
print(in_t.iloc[i][0] + "重复")
if(i == (len(re) - 1)):
print("查重已完成", end="\n\n")
result_lack = ref_s_lack - in_s
result_all = ref_s_all - in_s
if (mode == 0): # 查人除教改班
out_t = pd.concat([out_t, pd.Series(list(result_lack))],
axis=0, ignore_index=True)
print("除教改查人完毕")
elif (mode == 1): # 查人全体
out_t = pd.concat([out_t, pd.Series(list(result_all))],
axis=0, ignore_index=True)
print("全体查人完毕")
if (mode == 20): # 混排除教改班(剩)
temp = list(result_lack)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("剩下的同学混排完毕(除教改)")
elif (mode == 21): # 混排全体(剩)
temp = list(result_all)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("剩下的同学混排完毕(全体)")
if (mode == 30): # 混排输入(全)
temp = list(in_s)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("输入名单混排完毕")
elif (mode == 31): # 混排全体(除教改)(全)
temp = list(ref_s_lack)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("全体混排完毕(除教改)")
elif (mode == 32): # 混排全体(全)(全)
temp = list(ref_s_all)
random.shuffle(temp)
temp = pd.DataFrame(temp)
out_t = pd.concat([out_t, temp], axis=0, ignore_index=True)
print("全体混排完毕(含教改)")
if (mode == 40): # 随机抽人(除教改)
out_t = pd.concat([out_t, pd.DataFrame(random.sample(list(ref_s_lack), k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(除教改)已完成,共抽取{}人".format(num_pick))
elif (mode == 41): # 随机抽人(全)
out_t = pd.concat([out_t, pd.DataFrame(random.sample(list(ref_s_all), k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(全)已完成,共抽取{}人".format(num_pick))
elif (mode == 42): # 随机抽人(男)(除教改)
temp_list = []
for i in range(len(ref_t_lack)):
if (ref_t_lack.iloc[i][2] == "男"):
temp_list.append(ref_t_lack.iloc[i][0])
out_t = pd.concat([out_t, pd.DataFrame(random.sample(temp_list, k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(男)(除教改)已完成,共抽取{}人".format(num_pick))
elif (mode == 43): # 随机抽人(女)(除教改)
temp_list = []
for i in range(len(ref_t_lack)):
if (ref_t_lack.iloc[i][2] == "女"):
temp_list.append(ref_t_lack.iloc[i][0])
out_t = pd.concat([out_t, pd.DataFrame(random.sample(temp_list, k=num_pick))],
axis=0, ignore_index=True)
print("随机抽人(女)(除教改)已完成,共抽取{}人".format(num_pick))
out_t.to_excel(os.getcwd() + "\\out.xlsx", header=None, index=False)
mode = int(sys.argv[1])
try:
num_pick = int(sys.argv[2])
except:
num_pick = pd.NA
ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t = Initialize()
filter(mode, ref_s_lack, ref_t_lack, ref_s_all, in_t, in_s, out_t, num_pick)