title: How to create a separate CSV file for each day in face based attendance rather than overwriting the the existing one
body: <p>In this code attendance get marked in &quot;attendance.csv&quot; file. What I want is to create separate &quot;attendance.csv&quot; day wise, rather than overwriting the existing file, so that I can trace back past attendance if any conflicts from employee arise in future. <strong>I am unable to think and produce how it can be achieved.</strong></p>
  <p>Attendance CSV file contains the following entries:</p>
  <pre><code>ID,NAME,ATTENDANCE,EMAIL
  12,sk,1,sk12@gmail.com
  15,Aratrika Kosta,0,ak15@gmail.com
  </code></pre>
  <p>Programming language used Python.</p>
  <pre><code>def marking():
      df = pd.read_csv(&quot;CSV_files//attendance.csv&quot;)
     # df.loc[:,&quot;ATTENDANCE&quot;] = 0 # default attendance value (absent)
     # df.to_csv(&quot;CSV_files//attendance.csv&quot;,mode = 'w', index=False)
  
      def assure_path_exists(path): #if path not exists create path
          dir = os.path.dirname(path)
          if not os.path.exists(dir):
              os.makedirs(dir)
  
      
      recognizer = cv2.face.LBPHFaceRecognizer_create()
      assure_path_exists(&quot;trainer/&quot;)
      recognizer.read('trainer/trainer.yml')
      cascadePath = &quot;haarcascade_frontalface_default.xml&quot;
      faceCascade = cv2.CascadeClassifier(cascadePath);
      font = cv2.FONT_HERSHEY_SIMPLEX
      cam = cv2.VideoCapture(0)
  
      while True:
          # Read the video frame
          ret, im =cam.read()
  
          # Convert the captured frame into grayscale
          gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
  
          # Get all face from the video frame
          faces = faceCascade.detectMultiScale(gray, 1.2,5)
  
          # For each face in faces
          for(x,y,w,h) in faces:
  
              # Create rectangle around the face
              cv2.rectangle(im, (x-20,y-20), (x+w+20,y+h+20), (0,255,0), 4)
  
              # Recognize the face belongs to which ID
              Id, confidence = recognizer.predict(gray[y:y+h,x:x+w])
              
              
              print(confidence)
              #confidence--&gt;0 (best) , more the value of confidence lesser will be accuracy
              if confidence&gt;80: 
                  continue
              
              else:
                  imgdict = dict()
                  df = pd.read_csv(&quot;CSV_files//attendance.csv&quot;)
                  #Names and Ids as imgdict
                  diction = dict(df.loc[:,'ID']) #making dict from ID and NAME columns
                  imgdict = {}
                  for key,vals in diction.items():
                      imgdict[key+1] = vals
  
                  # Check the ID if exist 
                  for k,v in imgdict.items(): #looping through all keys
                      #print(k, type(k), v)
                      if (v==Id):
                          Id = v #if key is matched with recognizer Id , then assign Id=valueofimgdict
                          df = pd.read_csv(&quot;CSV_files//attendance.csv&quot;)
                          df.loc[k-1,&quot;ATTENDANCE&quot;]= 1  #student is present
                          # df.loc[:,&quot;ATTENDANCE&quot;]= 1  #student is present
                          df.to_csv(&quot;CSV_files//attendance.csv&quot;,mode = 'w', index=False)
                           
                  # Put text describe who is in the picture
                  cv2.rectangle(im, (x-22,y-90), (x+w+22, y-22), (0,255,0), -1) #-1--&gt;filled rectangle
                  cv2.putText(im, str(Id), (x,y-40), font, 1, (255,255,255), 3) #1 is size , 3 is thickness
  
          # Display the video frame with the bounded rectangle
          cv2.imshow('im',im) 
  
          # If 'q' is pressed, close program
          if cv2.waitKey(10) &amp; 0xFF == ord('q'):
              break
  
      # Stop the camera
      cam.release()
  
      # Close all windows
  
      cv2.destroyAllWindows()
  </code></pre>