76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
|
|
import pandas as pd
|
||
|
|
import os
|
||
|
|
|
||
|
|
curdir = os.getcwd()
|
||
|
|
path_delim = '/'
|
||
|
|
df1 = pd.read_excel(curdir + path_delim + "data/users_12_01_2024_23_25.xlsx", sheet_name="Sheet1")
|
||
|
|
df2 = pd.read_excel(curdir + path_delim + "data/12jan-printing-input.xlsx", sheet_name="Sheet1")
|
||
|
|
|
||
|
|
# Define a function to find the _id for each row in df2
|
||
|
|
def find_id(row):
|
||
|
|
match = df1[(df1['abhaId'] == row['abhaId'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['_id']
|
||
|
|
else:
|
||
|
|
match = df1[(df1['name'] == row['name'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['_id']
|
||
|
|
match = df1[(df1['house'] == row['address'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['_id']
|
||
|
|
return None
|
||
|
|
|
||
|
|
def find_aadharId(row):
|
||
|
|
match = df1[(df1['abhaId'] == row['abhaId'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['aadharId']
|
||
|
|
else:
|
||
|
|
match = df1[(df1['name'] == row['name'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['aadharId']
|
||
|
|
match = df1[(df1['house'] == row['address'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['aadharId']
|
||
|
|
return None
|
||
|
|
|
||
|
|
def find_abhaId(row):
|
||
|
|
match = df1[(df1['name'] == row['name'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['abhaId']
|
||
|
|
else:
|
||
|
|
match = df1[(df1['house'] == row['address'])]
|
||
|
|
if not match.empty:
|
||
|
|
return match.iloc[0]['abhaId']
|
||
|
|
return None
|
||
|
|
|
||
|
|
# Apply the function to create a new '_id' column in df2
|
||
|
|
df2['_id'] = df2["Photograph"].get_url()
|
||
|
|
df2['aadharId'] = df2.apply(find_aadharId, axis=1)
|
||
|
|
df2['abhaId2'] = df2.apply(find_abhaId, axis=1)
|
||
|
|
|
||
|
|
# Continue with the rest of your code...
|
||
|
|
|
||
|
|
# Add the rest of your code (e.g., renaming columns, creating new columns, etc.)
|
||
|
|
df2["Block/Ward"] = ""
|
||
|
|
# df2["Village/Town/City"] = df2["city"]
|
||
|
|
df2["Test Type"] = "HPOS"
|
||
|
|
df2["Photograph"] = df2['_id'].apply(lambda x: f'images\{x}.jpg')
|
||
|
|
|
||
|
|
df2.rename(columns={'_id': "Sample ID", "name": "Name", "aadharId": "AADHAAR ID", "ABHA ID": "ABHA Number", "careOf": "Father's Name / Husband's Name", "Test Result": "Test report"}, inplace=True)
|
||
|
|
|
||
|
|
# Continue with the rest of your code...
|
||
|
|
|
||
|
|
# Save the resulting DataFrame to Excel
|
||
|
|
writer = pd.ExcelWriter(curdir + path_delim + "data/CardPrint10.xlsx", engine='xlsxwriter')
|
||
|
|
df2.to_excel(writer, sheet_name='op', index=False)
|
||
|
|
|
||
|
|
# Get the xlsxwriter workbook and worksheet objects
|
||
|
|
workbook = writer.book
|
||
|
|
worksheet = writer.sheets['op']
|
||
|
|
|
||
|
|
# Add hyperlinks to the 'Photograph' column
|
||
|
|
for row_num, link in enumerate(df2['Photograph'], start=1):
|
||
|
|
worksheet.write_url(row_num, df2.columns.get_loc('Photograph'), string=link, url=link, cell_format=None)
|
||
|
|
|
||
|
|
writer.close()
|