需求:照片信息
通过导出的表格与照片进行分类
表格样式
解析:
表格的人员编号+姓名+0 与照片符合即可通过此办法找到所需照片
import os
import pandas
file = r'D:\Mr.Deer\Desktop\info.xlsx'
photo = 'D:\Mr.Deer\Desktop\photo\\'
//converters={u'*人员编号':str} 意思时将数字改为字符串,python默认为数字
df = pandas.read_excel(file,converters={u'*人员编号':str})
infodata = pandas.DataFrame(df).values
for i in range(0,len(infodata)):
data_each = []
data_each = infodata[i]
photo_file = data_each[0]+"_"+data_each[2]+"_0"
file_photo = data_each[1].split('/')
# print(file_photo[1])
new_file_photo = photo+file_photo[1]
print(new_file_photo)
if not os.path.exists(new_file_photo):
os.makedirs(new_file_photo)
print("已创建")
try:
os.rename(photo+photo_file+".jpg", new_file_photo+"\\{}.jpg".format(data_each[2]))
except:
pass
continue
最终效果呈现
![](https://img2022.cnblogs.com/blog/2306957/202210/2306957-20221006005746886-678403365.png)