詳細を私の問題を教えてください...私はそれが私のデータベースに存在する場合認識されている人の名前を出力するループを持っているそれ以外の場合は認識されません、そしてFORループが私にその名前を出力し、その名前をExcelシート(すなわちDATAFRAME)に保存したいが、FORループが最後の反復で与える名前とそれ以前に出力した他の名前反復が、それは間違いなく、再び書き込みの上にやって、もう一度ここに私の完全なコードです、失われ、特にpythonはパンダでexcelを生成します
from scipy.spatial import distance
import csv
import dlib
import os
import numpy as np
import cv2
import pandas as pd
from skimage import io
import face_recognition
from PIL import Image
with open("Data/train.csv","r") as facefeatures2:
reader=csv.reader(facefeatures2)
featureslist2=[]
for row in reader:
if len(row) != 0:
featureslist2= featureslist2 +[row]
facefeatures2.close()
float_int2=[]
results=[]
for f2 in range(0,len(featureslist2)):
float_int2 = float_int2 +[[float(str) for str in subarray] for subarray in [featureslist2[f2]]]
csv2 = np.vstack(float_int2)
faces_folder_path = "Data/newcropped"
list = os.listdir(faces_folder_path) # dir is your directory path
number_files = len(list)
print (number_files)
writer = pd.ExcelWriter('pandas_name11.xlsx', engine='xlsxwriter')
for loop in range(0,number_files):
print("iteration ="+str(loop+1))
unknown_image = face_recognition.load_image_file(faces_folder_path + "/" + str(loop+1)+".jpg")
cv2.imshow("test",unknown_image)
cv2.waitKey(0)
#### --------------exception handling-----------####
try:
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
except IndexError:
print("--->image is not detectable")
pass
# ...........................#
results = face_recognition.compare_faces(csv2, unknown_face_encoding)
chunks=[results[x:x + 12] for x in range(0, len(results),12)] # splits "results" list into sublists of size 12
dirpath = "Data/eachperson"
fname = []
fname = [f for f in sorted(os.listdir(dirpath))]
counter = 0
index=0
for c in range (0,len(chunks)):
if 'True' in str(chunks[c]):
counter=counter+1
index=c
df = pd.DataFrame({'names': [fname[index]]})
df.to_excel(writer, sheet_name='Sheet1')
if counter !=1 or counter ==0 :
print("student is not present :(")
else:
print(str(fname[index])+" is present!!!")
writer.save()
【それぞれのシート使用してPythonでExcelを既存に更新SQL出力データ]の可能な重複(https://stackoverflow.com/questions/45674596/update-sql-output-data-into-existing-excel-それぞれのシートを使用したパイソン) – silvanoe