From fcf07068810aeaca0f4e41f05315ac953a2068f3 Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Tue, 19 Sep 2023 11:33:48 +0530 Subject: [PATCH] combine pasr sheet --- scripts/combine2.py | 140 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 scripts/combine2.py diff --git a/scripts/combine2.py b/scripts/combine2.py new file mode 100644 index 0000000..f384248 --- /dev/null +++ b/scripts/combine2.py @@ -0,0 +1,140 @@ +import pandas as pd +import os + +curdir = os.getcwd() +path_delim = '/' +df1 = pd.read_csv(curdir + path_delim + "data/all_users_14_07_2023_to_12_09_2023.csv") +df2 = pd.read_csv(curdir + path_delim + "data/tests_14_07_2023_to_12_09_2023.csv") +df4 = pd.read_excel(curdir + path_delim + "data/Jul 26_30 2023_FinalDeclare.xlsx", sheet_name="results") +df5 = pd.read_excel(curdir + path_delim + "data/Jul31-Aug5 2023_FinalDeclare.xlsx", sheet_name="Result") +df_sept1 = pd.read_excel(curdir + path_delim + "data/NagpurData_FinalResults_Aug1 Shared.xlsx", sheet_name="Sheet1") +df_sept3 = pd.read_excel(curdir + path_delim + "data/Sept 3 Final Result Declared.xlsx", sheet_name="Sheet1") +df_sept4 = pd.read_excel(curdir + path_delim + "data/Final Results Sept 4.xlsx", sheet_name="Sheet1") +df_sept5 = pd.read_excel(curdir + path_delim + "data/September 5 Final Results.xlsx", sheet_name="Sheet1") +df_sept6 = pd.read_excel(curdir + path_delim + "data/FinalResults 6 Sept.xlsx", sheet_name="Sheet3") +df_sept7 = pd.read_excel(curdir + path_delim + "data/Final Results 07-Sept.xlsx", sheet_name="Sheet1") +df_sept8 = pd.read_excel(curdir + path_delim + "data/FinalResults 8 Sept.xlsx", sheet_name="Sheet1") +df6 = pd.read_excel(curdir + path_delim + "data/FinalResults - 9 Sept. 2023.xlsx", sheet_name="Sheet1") +df7 = pd.read_excel(curdir + path_delim + "data/FinalResults - 11 Sept 2023.xlsx", sheet_name="Sheet3") +df8 = pd.read_excel(curdir + path_delim + "data/FinalResults Sept 12-13, 2023.xlsx", sheet_name="Sheet1") + +### merging all user data for master +df = df1.merge(df2, on="_id") +# df = df.merge(df4, on="_id") +df['Age'] = 2023 - df['birthYear_x'] +# print(df.columns) +# print(df) +master_df = df + +### merging Jul 26 to 30 +df = master_df.merge(df4, on="aadharId") + +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "Test Result", "bloodGroup", "testTime"]] + +# 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", "Test Result": "Test Result", "bloodGroup": "Blood Group", "Age_x": "Age", "name_x": "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 July 31 - Aug 5 +df = master_df.merge(df5, on="aadharId") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "Test Result", "bloodGroup", "testTime"]] + +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", "Test Result": "Test Result", "bloodGroup": "Blood Group", "Age_x": "Age", "name_x": "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 + + +### merging Sept 1 +df_result_sept1 = df_sept1 + +### merging Sept 3 +df = master_df.merge(df_sept3, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "Test Result", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "bloodGroup": "Blood Group", "Age_x": "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_sept3 = df + + +### merging Sept 4 +df = master_df.merge(df_sept4, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "HPLC Results", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "HPLC Results": "Test Result", "bloodGroup": "Blood Group", "Age_x": "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_sept4 = df + + +### merging Sept 5 +df = master_df.merge(df_sept5, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "HPLC Results", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "HPLC Results": "Test Result", "bloodGroup": "Blood Group", "Age_x": "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_sept5 = df + +### merging Sept 6 +df = master_df.merge(df_sept6, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "Classification", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "Classification": "Test Result", "bloodGroup": "Blood Group", "Age_x": "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_sept6 = df + + +### merging Sept 7 +df = master_df.merge(df_sept7, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "HPLC", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "HPLC": "Test Result", "bloodGroup": "Blood Group", "Age_x": "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_sept7 = df + +### merging Sept 8 +df = master_df.merge(df_sept8, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age_x", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "HPLC", "bloodGroup", "testTime"]] +df.rename(columns={'_id': "Sample ID", "name_x": "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", "HPLC": "Test Result", "bloodGroup": "Blood Group", "Age_x": "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_sept8 = df + +### merging Sept 9 +df = master_df.merge(df6, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "Denovix Classification", "bloodGroup", "testTime"]] +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", "Denovix Classification": "Test Result", "bloodGroup": "Blood Group", "Age_x": "Age", "name_x": "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_3 = df + + + +### merging Sept 11 +df = master_df.merge(df7, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "classification-Estimated Denovix", "bloodGroup", "testTime"]] +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", "classification-Estimated Denovix": "Test Result", "bloodGroup": "Blood Group", "Age_x": "Age", "name_x": "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_4 = df + + +### merging Sept 12, 13 +df = master_df.merge(df8, on="_id") +df = df[["_id", "name_x", "abhaId", "aadharId", "Age", "gender", "category", "maritalStatus", "house", "district", "state", "pinCode", "phoneNumber", "classification-Estimated Denovix", "bloodGroup", "testTime"]] +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", "classification-Estimated Denovix": "Test Result", "bloodGroup": "Blood Group", "Age_x": "Age", "name_x": "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_5 = df + +### append all results +df_final = pd.concat([df_result_1, df_result_2, df_result_sept1, df_result_sept3, df_result_sept5, df_result_sept6, df_result_sept7, df_result_sept8, df_result_3, df_result_4, df_result_5]) + +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' + +print(df_final.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() \ No newline at end of file