import pandas as pd
filename1 = '电信1712班2019寒假返校统计.csv'
filename2 = '电信1712人员名单.csv'
names_x = []
with open(filename1) as f:
df = pd.read_csv(f, encoding = 'utf-8', usecols=['姓名'])
names1 = []
for index, row in df.iterrows():
names1.append(row["姓名"])
# print(names1)
with open(filename2) as f:
df = pd.read_csv(f, encoding = 'utf-8')
names2 = []
for index, row in df.iterrows():
names2.append(row["姓名"])
# print(names2)
for name in names2:
if name not in names1:
names_x.append(name)
print(names_x)
python自带的csv库对中文不是很友好,一直因为编码问题而报错,因此使用了pandas
关于pandas遍历,参考了这片博主的文章https://blog.csdn.net/ls13552912394/article/details/79349809
#代码的大致思路
将搜集到的数据,取出性名列,保存为csv格式,迭代将名字保存进names1列表中
将原有的班级名单excel表,单单保留姓名列,转换成csv格式另存为,迭代将名字保存进names2列表
用in/not in 语句判断,截至将搜集数据导出为csv格式的时间点,哪些同学还未提交
转载自原文链接, 如需删除请联系管理员。
原文链接:人名查询,转载请注明来源!