import pandas as pd import os curdir = os.getcwd() path_delim = '/' df1 = pd.read_excel(curdir + path_delim + "data/Testright 05 unreported data to be shated.xlsx", sheet_name="Sheet1") df2 = pd.read_excel(curdir + path_delim + "data/Testright 05 unreported data to be shated.xlsx", sheet_name="Sheet2") df3 = pd.read_excel(curdir + path_delim + "data/July_Sept_12_shared.xlsx", sheet_name="op") ### merging July df1['Age'] = 2023 - df1['birthYear'] df = df1[["_id", "name", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "bloodGroup", "testTime", "Class"]] # df = df.sort_values(by=['testTime'], ascending=True) df.rename(columns={'_id': "Sample ID", "name": "Name", "abhaId": "ABHA ID", "aadharId": "Aadhaar ID", "gender": "Gender", "category": "Category", "maritalStatus": "Marital Status", "house": "Address", "district": "District", "state": "State", "pinCode": "Pincode", "phoneNumber": "Mobile Number", "testTime": "Test Time", "Class": "Test Result", "bloodGroup": "Blood Group", "Age": "Age", "name": "Name"}, inplace = True) df = df.reindex(["Sample ID", "Name", "ABHA ID", "Aadhaar ID", "Age", "Gender", "Category", "Marital Status", "Address", "District", "State", "Pincode", "Mobile Number", "Test Time", "Test Result", "Blood Group"], axis=1) df_result_1 = df ### merging Aug 5 to 30 df2['Age'] = 2023 - df2['birthYear'] df = df2[["_id", "name", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "bloodGroup", "testTime", "Class"]] # df = df.sort_values(by=['testTime'], ascending=True) df.rename(columns={'_id': "Sample ID", "name": "Name", "abhaId": "ABHA ID", "aadharId": "Aadhaar ID", "gender": "Gender", "category": "Category", "maritalStatus": "Marital Status", "house": "Address", "district": "District", "state": "State", "pinCode": "Pincode", "phoneNumber": "Mobile Number", "testTime": "Test Time", "Class": "Test Result", "bloodGroup": "Blood Group", "Age": "Age", "name": "Name"}, inplace = True) df = df.reindex(["Sample ID", "Name", "ABHA ID", "Aadhaar ID", "Age", "Gender", "Category", "Marital Status", "Address", "District", "State", "Pincode", "Mobile Number", "Test Time", "Test Result", "Blood Group"], axis=1) df_result_2 = df # ### append all results df_final = pd.concat([df_result_1, df_result_2, df3]) print(df_final) df_final.loc[df_final['Test Result'] == 'Normal', 'Test Result'] = 'Normal (HbA)' df_final.loc[df_final['Test Result'] == 'Sickle Cell Trait', 'Test Result'] = 'Sickle Cell Trait (HbAS)' df_final.loc[df_final['Test Result'] == 'SCT', 'Test Result'] = 'Sickle Cell Trait (HbAS)' df_final.loc[df_final['Test Result'] == 'SCD', 'Test Result'] = 'Sickle cell Disease (HbSS)' df_final.loc[df_final['Test Result'] == 'PBL', 'Test Result'] = 'Positive Borderline' df_final.loc[df_final['Test Result'] == 'NBL', 'Test Result'] = 'Negative Borderline' df_final.loc[df_final['Gender'] == 'Male', 'Gender'] = 'MALE' df_final.loc[df_final['Gender'] == 'Female', 'Gender'] = 'FEMALE' # #df_final = df.drop_duplicates(subset=['Sample ID', "Test Time"], keep='last') # df_dedup = pd.read_excel(curdir + path_delim + "data/July_Sept_12_shared.xlsx", sheet_name="op") # print(df_dedup) # print(df_dedup.groupby(["Gender"]).describe()) writer = pd.ExcelWriter(curdir + path_delim + "data/July_Sept.xlsx", engine = 'openpyxl') df_final.to_excel(writer, sheet_name = 'op', index=False) writer.close()