I have a pandas Dataframe, called relevant_URT_data, that looks like this:
test MRN Number ResCat
12 AP Disbursements Payment Details URT INC3778700 0
33 AP Disbursements Payment Details NaN INC3783080 0
72 AP Disbursements Payment Details URT INC3782671 0
150 AP Quality Assurance Payment Status URT INC3778770 0
178 PR HBS Inquiry NaN INC3776742 1
192 AP Quality Assurance Payment Status NaN INC3778547 0
315 AP Quality Assurance Payment Status URT INC3780548 0
328 PR Accounting W-2 Form URT INC3782016 0
355 AP General Submit Invoice for Payment URT INC3781884 0
374 AP General Inquiry NaN INC3775944 0
I use the following code to group the data by test - please see image below.
test_breakdown = relevant_URT_data[["test","MRN","Number"]] \
.groupby("test") \
.agg({'MRN':'count', 'Number':'size'}) \
.rename(columns={'MRN':'URT Use Count','Number':'Number'})
test URT Use Count Number
AP Connexxus Access Request 9 9
AP Disbursements Payment Details 28 35
AP General Inquiry 1 7
AP General Submit Invoice for Payment 25 27
AP General WebNow/Invoice Copies 0 4
AP MyExpense Access Request 3 3
AP MyExpense Grant Delegated Access 0 1
AP MyExpense Inquiry 2 8
AP Quality Assurance Payment Status 56 71
Controller's Office General Medical Center 7 10
PR Accounting W-2 Form 6 9
PR HBS Inquiry 0 17
PR HBS Timesheet Calculations 0 2
PR Processing and Production Direct Deposit 2 2
PR Processing and Production Payment Details 0 1
PR Verification of Employment How to Request VOE 1 1
PR Verification of Employment Written VOE 2 4
My goal is to add 2 more columns to the grouped dataset:
1) A column that shows 'URT Use Count' divided by 'Number' (I want the percentage of Number that is MRN) 2) A column that shows ResCat == 0 divided by Number (I want the percentage of Number that has ResCat equal to 0)
Here is optimally what I would want the output to look like- the two new columns are displayed below:
test URT Use Count Number Percentage_Use Same_Day_Percentage
AP Connexxus Access Request 9 9 100% 55%
AP Disbursements Payment Details 28 35 80% 77%
AP General Inquiry 1 7 14% 92%
AP General Submit Invoice for Payment 25 27 92% 97%
AP General WebNow/Invoice Copies 0 4 0% 19%
AP MyExpense Access Request 3 3 100% 50%
AP MyExpense Grant Delegated Access 0 1 0% 50%
AP MyExpense Inquiry 2 8 25% 77%
AP Quality Assurance Payment Status 56 71 79% 88%
Controller's Office General Medical Center 7 10 70% 20%
PR Accounting W-2 Form 6 9 67% 20%
PR HBS Inquiry 0 17 0% 100%
PR HBS Timesheet Calculations 0 2 0% 45%
PR Processing and Production Direct Deposit 2 2 100% 99%
PR Processing and Production Payment Details 0 1 0% 15%
PR Verification of Employment How to Request VOE 1 1 100% 12%
PR Verification of Employment Written VOE 2 4 50% 22%
Any clarification on creating these calculated fields would be extremely helpful.