最近は比較的のんびりしています。ネットワーキングイベントの入札に成功しました。他の2つの大学で開催されており、女子の割合が比較的高くなっています。登録フォームの作成は私が担当しています。13日から現在まで(19日の午前1時)、670人以上の学生が登録しており、男性と女性の比率は1:2になる傾向があります。
実際の学校のデータであるため、データは公開されません。登録フォームはアンケートスターが作成し、ダウンロードして元のデータフォームを取得しました。オリジナルの登録フォームは8つあります。名、2番目の性別、3番目の学位、4番目の大学、5番目の携帯電話番号が必要です。残りの半分の自己紹介と要件は次のとおりです。オプション。
アンケートスターからダウンロードしたエクセのフォーマットは以下の通りです。
0シリアル番号 | 1解答用紙を提出する時間 | 2回使用 | 3つのソース | 4ソースの詳細 | IPから5 | 6名前 | 7セックス | 8度 | 9所在学院 | 10携帯電話番号 | 11枚の個人写真 | 12自己紹介 | 残りの半分の13の要件 |
8つの質問について、名前、大学、携帯電話番号は空でない文字列、性別と教育はそれぞれオプションのシリアル番号を表す番号です。写真は添付ファイルの種類です。アップロードすると表示されます。写真のアドレスとして、それ以外の場合は文字列 '(Empty)'になり、紹介と要件が入力されている場合は対応する文字列になり、それ以外の場合は '(empty)'になります。
まず、大学の場合、略語を書くのが好きな人もいれば、完全なスペルを書く人もいます。たとえば、文化ジャーナリズム大学の場合、「Wen Xin」、「Wen Xin College」、「Culture andJournalismCollege」と記入する人もいます。 、など。統計を容易にするために、それらによって入力されたさまざまな大学名を調整する必要があります。だから私は手動でテーブルcollege_name.xlsを整理しました:
最初の列はQuanpinで、2番目の列はさまざまな入力方法で大学に対応するキーワードの組み合わせです。複数のスペースはスペースで区切られ、異なる大学のキーワードを同じにしたり、関係を含めたりすることはできません。
college_name=xlrd.open_workbook(r'collegename.xls')#打开表格
cn=college_name.sheet_by_index(0)#获得第一张表
dictionary=dict()#字典存放关键词到学院的映射
mapping=dict()#字典存放学院到编号的映射
map_number=0#学院编号
start_row=1;#遍历开始行数 第一行为表头,所以跳过
row=start_row;
while row<cn.nrows:#cn.nrows:cn的行数
wordset=re.split(' ',cn.cell_value(row,1))#通过split对多个关键词进行分割,放入wordset里
for word in wordset:
dictionary[word]=cn.cell_value(row,0)#将每个关键词到学院全拼的映射存在dictionary字典
if cn.cell_value(row,0) not in mapping:
mapping[cn.cell_value(row,0)]=map_number
map_number=map_number+1#如果学院名不在mapping的key中,则存入,并映射为map_number
row=row+1
操作が完了した後、キーワードの大学のフルネームへのマッピングと大学のフルネームの番号へのマッピングが取得され、各大学の男性と女性の応募者の数が保存されます。
signtable=xlrd.open_workbook(r'联谊活动报名表.xls')#原始表
st=signtable.sheet_by_index(0)
row=start_row;
statistic=np.zeros([len(mapping),6]);#每一行代表一个学院的男生报名数、女生报名数、总报名人数占比、男生占比、女生占比和男女比例 先计算前两列
while row<st.nrows:
college=st.cell_value(row,9);#或者原始输入的学院名
find=0;#标记是否找到
for keyword in dictionary:
if keyword in college:#如果dictionary的key中存在关键词是原始输入学院名的子串,则找到
find=1;#
statistic[mapping[dictionary[keyword]],int(st.cell_value(row,7)-1)]+=1
break#将对应学院所在行(mapping映射的值)的第1列或第2列(取决于性别)+1
if find==0:
print(college+'can not find')
row=row+1
次に、pltの円グラフを使用して円グラフを描画します。
import matplotlib.pyplot as plt
labels = [str(i) for i in range((len(mapping)))]
sizes = [(i[0]+i[1])for i in statistic]
plt.pie(sizes, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
plt.axis('equal')
plt.show()
結果:
中国語はデフォルトでサポートされていないため、各ブロックのラベルはマッピングマッピングの番号に設定されます。
最初のテーブルの作成を開始します。形式は次のとおりです。
0名前 | 1フォームに記入する時間 | 2つの大学 | 3性別 | 4つの学歴 | 5携帯電話番号 | 6写真のアップロード状況 | 7はじめに | 8つの要件 |
import xlwt
workspace=xlwt.Workbook(encoding='ascii')
excel=workspace.add_sheet('报名表完整版',cell_overwrite_ok=True)#添加第一张表
excel.write(0,0,'姓名')
excel.write(0,1,'填表时长/s')
excel.write(0,2,'学院')
excel.write(0,3,'性别')
excel.write(0,4,'学历')
excel.write(0,5,'手机号码')
excel.write(0,6,'照片上传情况')
excel.write(0,7,'介绍')
excel.write(0,8,'要求')#第一行添加表头
for row in range(1,st.nrows):
excel.write(row,0,st.cell_value(row,6))#写入姓名
excel.write(row,1,st.cell_value(row,2)[0:-1])#原始数据为'xxx秒',为了方便以后筛选,在这去掉最后一个字符,故设置为取0:-1
temp_college=st.cell_value(row,9)#原始学院名输入
for keyword in dictionary:
if keyword in temp_college:
excel.write(row,2,dictionary[keyword])#将在字典中查到的完整学院名写入
excel.write(row,3,st.cell_value(row,7))#写入性别
excel.write(row,4,st.cell_value(row,8))#写入学历
excel.write(row,5,st.cell_value(row,10))#写入手机号码
if st.cell_value(row,11)=='(空)':#如果照片未上传,则写为0,否则写入1
excel.write(row,6,0)
else:
excel.write(row,6,1)
excel.write(row,7,st.cell_value(row,12))#写入介绍
excel.write(row,8,st.cell_value(row,13))#写入要求
同様に、その時点でグループに公開するための2番目のテーブルを作成し、テーブルの内容に応じて一致させて、携帯電話番号と性別を部分的に非表示にします。読みやすくするために、jiebaを使用して、紹介のコアワードとそれらによって書かれた要件を抽出します。
import jieba.posseg as posseg
excel2=workspace.add_sheet('报名表简洁版',cell_overwrite_ok=True)
excel2.write(0,0,'姓名')
excel2.write(0,1,'填表时长/s')
excel2.write(0,2,'学院')
excel2.write(0,3,'性别')
excel2.write(0,4,'学历')
excel2.write(0,5,'手机号码')
excel2.write(0,6,'照片上传情况')
excel2.write(0,7,'介绍')
excel2.write(0,8,'要求')
word_type=['n','nz','ns','vn','v','a','an']#保留的词性
for row in range(1,st.nrows):
temp_name=st.cell_value(row,6)
if len(temp_name)==2:
write_name=temp_name[0]+'*'
elif len(temp_name)==3:
write_name=temp_name[0]+'*'+temp_name[2]
else:
write_name=temp_name[0]+'**'+temp_name[3]
excel2.write(row,0,write_name)#对姓名的第一个字改为*,四字名字的第二三个字改为*
excel2.write(row,1,st.cell_value(row,2)[0:-1])
temp_college=st.cell_value(row,9)
for keyword in dictionary:
if keyword in temp_college:
excel2.write(row,2,dictionary[keyword])
excel2.write(row,3,st.cell_value(row,7))
excel2.write(row,4,st.cell_value(row,8))
excel2.write(row,5,str(st.cell_value(row,10)[:3])+'****'+str(st.cell_value(row,10)[-4:]))#手机号码的中间四位改为*
if st.cell_value(row,11)=='(空)':
excel2.write(row,6,0)
else:
excel2.write(row,6,1)
words_info = posseg.cut(st.cell_value(row,12))
words_demm = posseg.cut(st.cell_value(row,13))#对他们的介绍和要求进行词性切分
info=''
demm=''
for word, flag in words_info:
if flag in word_type:
info+=word#遍历切分后的每一个词word和他的词性flag,如果词性满足要求,则添加改词
for word, flag in words_demm:
if flag in word_type:
demm+=word
excel2.write(row,7,info)
excel2.write(row,8,demm)
関連する品詞は次のとおりです。
a | 形容詞 |
AN | 名詞 |
d | 副詞 |
e | 間投詞 |
m | 数量詞 |
n | 名詞 |
ns | 地名 |
番号 | 人名 |
nt | 組織名 |
nz | 他の名前 |
v | 動詞 |
vn | 動名詞 |
統計の3〜6列を計算し、各大学に書き込まれるデータ統計として3番目のテーブルに書き込みます。
excel3=workspace.add_sheet('数据统计',cell_overwrite_ok=True)
excel3.write(0,0,'学院名')
excel3.write(0,1,'报名人数')
excel3.write(0,2,'总占比')
excel3.write(0,3,'男生报名数')
excel3.write(0,4,'男生占比')
excel3.write(0,5,'女生报名数')
excel3.write(0,6,'女生占比')
excel3.write(0,7,'男女比例')
number=1
for college in mapping:
excel3.write(number,0,college)#第三张表写入学院名
boy=statistic[mapping[college],0];#获得该学院男生报名数,之前计算得
girl=statistic[mapping[college],1];
print(college+'总报名人数'+str(boy+girl))
excel3.write(number,1,str(boy+girl))#第二列写入总数
excel3.write(number,3,str(boy))#第四列写入男生人数
excel3.write(number,5,str(girl))#第六列写入女生人数
statistic[mapping[college],2]=round((boy+girl)/st.nrows,5)#储存数据在变量statistic里
print('占'+str(statistic[mapping[college],2]))
statistic[mapping[college],3]=round(boy/191,3)#
statistic[mapping[college],4]=round(girl/384,3)
if girl==0:
girl=1#在计算男女比例时可能出现分母(女生为0)的情况,故设置为1
statistic[mapping[college],5]=round(boy/girl,3)
excel3.write(number,2,str(100*statistic[mapping[college],2])+'%')#分别百分数写入占比
excel3.write(number,4,str(100*statistic[mapping[college],3])+'%')
excel3.write(number,6,str(100*statistic[mapping[college],4])+'%')
excel3.write(number,7,str(statistic[mapping[college],5]))
print('男生占'+str(statistic[mapping[college],3]))
print('女生占'+str(statistic[mapping[college],4]))
print('男女比例'+str(statistic[mapping[college],5]))
number+=1
最後にテーブルを保存します(今書いたばかりのexcel、excel2、excel3が含まれています)
workspace.save('报名表.xls')
完全なコード:
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 16 17:20:04 2019
@author: 71405
"""
import xlrd
import re
import numpy as np
college_name=xlrd.open_workbook(r'collegename.xls')
cn=college_name.sheet_by_index(0)
dictionary=dict()
mapping=dict()
map_number=0
start_row=1;
row=start_row;
while row<cn.nrows:#cn.nrows:行数
wordset=re.split(' ',cn.cell_value(row,1))
for word in wordset:
dictionary[word]=cn.cell_value(row,0)
if cn.cell_value(row,0) not in mapping:
mapping[cn.cell_value(row,0)]=map_number
map_number=map_number+1
row=row+1
signtable=xlrd.open_workbook(r'联谊活动报名表.xls')
st=signtable.sheet_by_index(0)
row=start_row;
statistic=np.zeros([len(mapping),6]);
while row<st.nrows:
college=st.cell_value(row,9);
find=0;
for keyword in dictionary:
if keyword in college:
find=1;
statistic[mapping[dictionary[keyword]],int(st.cell_value(row,7)-1)]+=1
break
if find==0:
print(college+'can not find')
row=row+1
import matplotlib.pyplot as plt
labels = [str(i) for i in range((len(mapping)))]
sizes = [(i[0]+i[1])for i in statistic]
plt.pie(sizes, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
plt.axis('equal')
plt.show()
import jieba.posseg as posseg
import xlwt
workspace=xlwt.Workbook(encoding='ascii')
excel=workspace.add_sheet('报名表完整版',cell_overwrite_ok=True)
excel.write(0,0,'姓名')
excel.write(0,1,'填表时长/s')
excel.write(0,2,'学院')
excel.write(0,3,'性别')
excel.write(0,4,'学历')
excel.write(0,5,'手机号码')
excel.write(0,6,'照片上传情况')
excel.write(0,7,'介绍')
excel.write(0,8,'要求')
for row in range(1,st.nrows):
excel.write(row,0,st.cell_value(row,6))
excel.write(row,1,st.cell_value(row,2)[0:-1])
temp_college=st.cell_value(row,9)
for keyword in dictionary:
if keyword in temp_college:
excel.write(row,2,dictionary[keyword])
excel.write(row,3,st.cell_value(row,7))
excel.write(row,4,st.cell_value(row,8))
excel.write(row,5,st.cell_value(row,10))
if st.cell_value(row,11)=='(空)':
excel.write(row,6,0)
else:
excel.write(row,6,1)
excel.write(row,7,st.cell_value(row,12))
excel.write(row,8,st.cell_value(row,13))
excel2=workspace.add_sheet('报名表简洁版',cell_overwrite_ok=True)
excel2.write(0,0,'姓名')
excel2.write(0,1,'填表时长/s')
excel2.write(0,2,'学院')
excel2.write(0,3,'性别')
excel2.write(0,4,'学历')
excel2.write(0,5,'手机号码')
excel2.write(0,6,'照片上传情况')
excel2.write(0,7,'介绍')
excel2.write(0,8,'要求')
word_type=['n','nz','ns','vn','v','a','an']
for row in range(1,st.nrows):
temp_name=st.cell_value(row,6)
if len(temp_name)==2:
write_name=temp_name[0]+'*'
elif len(temp_name)==3:
write_name=temp_name[0]+'*'+temp_name[2]
else:
write_name=temp_name[0]+'**'+temp_name[3]
excel2.write(row,0,write_name)
excel2.write(row,1,st.cell_value(row,2)[0:-1])
temp_college=st.cell_value(row,9)
for keyword in dictionary:
if keyword in temp_college:
excel2.write(row,2,dictionary[keyword])
excel2.write(row,3,st.cell_value(row,7))
excel2.write(row,4,st.cell_value(row,8))
excel2.write(row,5,str(st.cell_value(row,10)[:3])+'****'+str(st.cell_value(row,10)[-4:]))
if st.cell_value(row,11)=='(空)':
excel2.write(row,6,0)
else:
excel2.write(row,6,1)
words_info = posseg.cut(st.cell_value(row,12))
words_demm = posseg.cut(st.cell_value(row,13))
info=''
demm=''
for word, flag in words_info:
if flag in word_type:
info+=word
for word, flag in words_demm:
if flag in word_type:
demm+=word
excel2.write(row,7,info)
excel2.write(row,8,demm)
excel3=workspace.add_sheet('数据统计',cell_overwrite_ok=True)
excel3.write(0,0,'学院名')
excel3.write(0,1,'报名人数')
excel3.write(0,2,'总占比')
excel3.write(0,3,'男生报名数')
excel3.write(0,4,'男生占比')
excel3.write(0,5,'女生报名数')
excel3.write(0,6,'女生占比')
excel3.write(0,7,'男女比例')
number=1
for college in mapping:
excel3.write(number,0,college)
boy=statistic[mapping[college],0];
girl=statistic[mapping[college],1];
print(college+'总报名人数'+str(boy+girl))
excel3.write(number,1,str(boy+girl))
excel3.write(number,3,str(boy))
excel3.write(number,5,str(girl))
statistic[mapping[college],2]=round((boy+girl)/st.nrows,5)
print('占'+str(statistic[mapping[college],2]))
statistic[mapping[college],3]=round(boy/191,3)
statistic[mapping[college],4]=round(girl/384,3)
if girl==0:
girl=1
statistic[mapping[college],5]=round(boy/girl,3)
excel3.write(number,2,str(100*statistic[mapping[college],2])+'%')
excel3.write(number,4,str(100*statistic[mapping[college],3])+'%')
excel3.write(number,6,str(100*statistic[mapping[college],4])+'%')
excel3.write(number,7,str(statistic[mapping[college],5]))
print('男生占'+str(statistic[mapping[college],3]))
print('女生占'+str(statistic[mapping[college],4]))
print('男女比例'+str(statistic[mapping[college],5]))
number+=1
workspace.save('报名表.xls')
———————————————————————私は境界線です—————————————————————— — —————
分析と処理が完了した後、応募者が多かったため、1つずつスクリーニングすることができなかった場合、スクリーニングアルゴリズムが作成されました。
フォームに記入する時間の長さ、写真をアップロードするかどうか、紹介文を書くかどうか、要件を書くかどうかの4つの条件によって制御されます。一般に、これらの4つの次元のデータは、学生が熱心で真剣であるかどうかを示すことができます。アクティビティ。たとえば、20代の生徒が記入を完了した後、記入できる3つのフィールドのいずれにも記入されていないため、落書きが多すぎます。多くのコンテンツを書き込んで写真をアップロードした生徒もいます。記入時間は100秒(データの最長の入力時間は2600秒で、おそらく20分以上です。真剣に見てください!)。
import xlrd
import xlwt
workspace=xlwt.Workbook(encoding='ascii')
excel=workspace.add_sheet('报名表筛选版',cell_overwrite_ok=True)
select_list=[1,1,1,1]#分别代表时间/照片/介绍/要求为空时是否筛选
col_num=[1,6,7,8]#四个属性所在列号
time_thre=100#阈值
table=xlrd.open_workbook(r'报名表.xls')#打开之前所写入完成的表的第一张
t=table.sheet_by_index(0)
remain=1#保留的行号
for i in range(t.ncols):#t.ncols:t的列数
excel.write(0,i,t.cell_value(0,i))#老规矩,第一行复制表头
for row in range(1,t.nrows):
state=True#表示是否保留
if select_list[0]==1:
if int(t.cell_value(row,col_num[0]))<time_thre:
state=False#填写时长小于阈值的置为不保留
for i in range(1,4):
if select_list[i]==1:#是否分别开启照片/介绍/要求非空筛选
if t.cell_value(row,col_num[i])=='0' or t.cell_value(row,col_num[i])==0 or t.cell_value(row,col_num[i])=='(空)' or t.cell_value(row,col_num[i])=='无':
state=False#如果对应字符串为无、空、0的任意字符,则不保留
if state:
for i in range(t.ncols):
excel.write(remain,i,t.cell_value(row,i))#如果以上都通过了则写入新表
remain+=1
workspace.save('报名表筛选版.xls')