Issue
So basically I am following this solution: Align value counts of two dataframes side by side
I am implementing the code, but instead of getting the result as shown in the answer posted by jezrael, I am getting this format (please note df_curr_obj, and df_old_obj are my 2 dataframes):
_id df_curr_obj [472d5fe8-7 - 1, 0e1eb4d8-5 - 1, 2996b2de-5 - 1]
_id_reason df_curr_obj [1348fbc6-7 - 1, 0ee0661f-d - 1, a8c03816-c - 1]
_rev df_curr_obj [v1 - 93, v2 - 1]
_rev_reason df_curr_obj [v1 - 92, v2 - 1]
baseentityid df_curr_obj [f32e9041-3 - 2, 4411bc0f-9 - 1, 1c7b44b1-d - 1]
baseentityid_reason df_curr_obj [4411bc0f-9 - 1, 9568a3b1-b - 1, aa6eacf4-c - 1]
current_pregnancy_id_reason df_curr_obj [790e4b21-2 - 1, 75d82e1a-c - 1, 1c89ec5d-5 - 1]
device_identifier df_curr_obj [648f1a44-6 - 31, 667a945a-f - 24, 30a009f9-c - 12]
device_identifier_reason df_curr_obj [648f1a44-6 - 31, 667a945a-f - 24, 30a009f9-c - 12]
edd df_curr_obj [02/08/2022 - 3, 01/11/2022 - 3, 23/10/2022 - 2]
entitytype df_curr_obj [1348fbc6-7 - 1, 0ee0661f-d - 1, 76b45696-0 - 1]
facility_reason df_curr_obj [Qayumabad - 31, Ali Akbar - 24, Bhains Col - 12]
fetalheartbeat df_curr_obj [PRESENT - 92]
formsubmissionid df_curr_obj [472d5fe8-7 - 1, 0e1eb4d8-5 - 1, 2996b2de-5 - 1]
formsubmissionid_reason df_curr_obj [1348fbc6-7 - 1, 0ee0661f-d - 1, a8c03816-c - 1]
lie df_curr_obj [LONGITUDIN - 29, OBLIQUE - 2, TRANSVERSE - 1]
liquordescription df_curr_obj [ADEQUATE - 78, SCANTY - 2, EXCESS - 1]
locationid df_curr_obj [AG - 24, BH - 12, IH - 7]
locationid_reason df_curr_obj [AG - 24, BH - 12, IH - 7]
otherfetalanomalies df_curr_obj [pleural ef - 1, unilateral - 1]
placenta_previa df_curr_obj [NO - 62, DONT_KNOW - 1, YES - 1]
placental_abruption df_curr_obj [NO - 63, DONT_KNOW - 2]
placentallocalization df_curr_obj [notLowLyin - 44, anteriorWa - 15, posteriorW - 10]
presence_of_fetal_anomalies df_curr_obj [others - 2]
presentation df_curr_obj [CEPHALIC - 30, BREECH - 2]
providerid df_curr_obj [qasonologi - 31, agsonologi - 24, bhsonologi - 12]
providerid_reason df_curr_obj [qasonologi - 31, agsonologi - 24, bhsonologi - 12]
serverversion df_curr_obj [2022-07-07 - 94]
serverversion_reason df_curr_obj [2022-07-07 - 93]
task_id df_curr_obj [2ad74e31-2 - 1, dcb1a9c5-e - 1, e835b894-f - 1]
task_id_reason df_curr_obj [2ad74e31-2 - 1, 2b450eb6-1 - 1, 4dda40a1-e - 1]
taskid_reason df_curr_obj [2ad74e31-2 - 1, 2b450eb6-1 - 1, 4dda40a1-e - 1]
team df_curr_obj [VITAL-QB - 31, VITAL-AG-A - 24, VITAL-BH-A - 12]
team_reason df_curr_obj [VITAL-QB - 31, VITAL-AG-A - 24, VITAL-BH-A - 12]
teamid df_curr_obj [VITAL-QB - 31, VITAL-AG-A - 24, VITAL-BH-A - 12]
teamid_reason df_curr_obj [VITAL-QB - 31, VITAL-AG-A - 24, VITAL-BH-A - 12]
ultrasound_reasons_reason df_curr_obj [[Gestation - 93]
ultrasoundreasons_reason df_curr_obj [[Gestation - 93]
version df_curr_obj [2022-07-07 - 94]
version_reason df_curr_obj [2022-07-07 - 93]
_id df_old_obj [4015790d-3 - 1, b106e1f3-5 - 1, 25880919-6 - 1]
_id_reason df_old_obj [46135f86-9 - 1, 4faeeeb6-0 - 1, c0995147-f - 1]
_rev df_old_obj [v1 - 47]
_rev_reason df_old_obj [v1 - 47]
baseentityid df_old_obj [c747f7bc-9 - 1, 5665e9c7-1 - 1, ee2b5683-a - 1]
baseentityid_reason df_old_obj [c747f7bc-9 - 1, 5665e9c7-1 - 1, ee2b5683-a - 1]
current_pregnancy_id_reason df_old_obj [5c8942f4-5 - 1, 2095aa4f-4 - 1, feab7c3f-7 - 1]
device_identifier df_old_obj [648f1a44-6 - 15, cb7fb229-9 - 10, 6e627f53-e - 8]
device_identifier_reason df_old_obj [648f1a44-6 - 15, cb7fb229-9 - 10, 6e627f53-e - 8]
edd df_old_obj [24/08/2022 - 2, 10/08/2022 - 2, 31/01/2023 - 2]
entitytype df_old_obj [46135f86-9 - 1, 4faeeeb6-0 - 1, c0995147-f - 1]
facility_reason df_old_obj [Qayumabad - 15, Sukhiya Go - 10, Ibrahim Hy - 8]
fetalheartbeat df_old_obj [PRESENT - 47]
formsubmissionid df_old_obj [4015790d-3 - 1, b106e1f3-5 - 1, 25880919-6 - 1]
formsubmissionid_reason df_old_obj [46135f86-9 - 1, 4faeeeb6-0 - 1, c0995147-f - 1]
lie df_old_obj [LONGITUDIN - 10, TRANSVERSE - 1]
liquordescription df_old_obj [ADEQUATE - 37, SCANTY - 1]
locationid df_old_obj [IH - 8, BH - 5, AG - 5]
locationid_reason df_old_obj [IH - 8, BH - 5, AG - 5]
placenta_previa df_old_obj [NO - 22, YES - 1]
placental_abruption df_old_obj [NO - 22]
placentallocalization df_old_obj [notLowLyin - 15, posteriorW - 7, anteriorWa - 5]
presentation df_old_obj [CEPHALIC - 10]
providerid df_old_obj [qasonologi - 15, sgsonologi - 10, ihsonologi - 8]
providerid_reason df_old_obj [qasonologi - 15, sgsonologi - 10, ihsonologi - 8]
serverversion df_old_obj [2022-07-06 - 47]
serverversion_reason df_old_obj [2022-07-06 - 47]
task_id df_old_obj [8edc3bd4-f - 1, 5b2c076a-3 - 1, 4eb35473-e - 1]
task_id_reason df_old_obj [8edc3bd4-f - 1, 5b2c076a-3 - 1, 4eb35473-e - 1]
taskid_reason df_old_obj [8edc3bd4-f - 1, 5b2c076a-3 - 1, 4eb35473-e - 1]
team df_old_obj [VITAL-QB - 15, VITAL-SG - 10, VITAL-IH-A - 8]
team_reason df_old_obj [VITAL-QB - 15, VITAL-SG - 10, VITAL-IH-A - 8]
teamid df_old_obj [VITAL-QB - 15, VITAL-SG - 10, VITAL-IH-A - 8]
teamid_reason df_old_obj [VITAL-QB - 15, VITAL-SG - 10, VITAL-IH-A - 8]
ultrasound_reasons_reason df_old_obj [[Gestation - 47]
ultrasoundreasons_reason df_old_obj [[Gestation - 47]
version df_old_obj [2022-07-06 - 47]
version_reason df_old_obj [2022-07-06 - 47]
dtype: object
I have tried increasing the the number of rows / columns displayed and increasing column width, but this has no affect.
Maybe it is because for some columns, there is only one or two value_counts (not 3)?
Solution
So I tried a few things myself, and the following code update gets the result close to the desired format:
df_final = pd.concat([df11, df22], axis=1, keys=('df_curr_obj','df_old_obj')).stack().sort_index()
Answered By - Ray92
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.