DataScience Sample Program to Match Record based on Date using Excel file


Step 1st:-  Create Excel file using following cell

FirstName DOB
Manish 4/12/2019
kapil 4/13/2019
kamal 4/15/2019
Jay 4/15/2019
ravi 1/30/2020
chk 2/1/2020

Step2nd:-  Write following code to match data from excel file:-

import xlrd 
import numpy as np
from datetime import date
today =
loc = ("Book1.xlsx") 
wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0)
current = today.strftime("%Y-%m-%d")
#current = '2020-1-30'
arr = np.array([int]*6)
y, m, d, h, i, s = xlrd.xldate_as_tuple(sheet.cell_value(1, 1), wb.datemode)
#print("{0}-{1}-{2}".format(y, m, d))
for i in range(1,sheet.nrows):
    y, m, d, h, i, s = xlrd.xldate_as_tuple(sheet.cell_value(i, 1), wb.datemode)
    arr[index]="{0}-{1}-{2}".format(y, '0'+str(m) if m<10 else m, '0'+str(d) if d<10 else d)
print(current in arr)


Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)