Skip to content
Advertisement

Sort multiIndex table based on other table

I have a multiIndex data frame like this

JavaScript

and I have another similar table whose index is Patient_1, Patient_2 and Patient_3. I want to order my table like that. Patients are actually names and the number of patients can change depending on the input data. In the table I want to re-order, there are 10 rows per patient, in the one with the patient in the right order, each patient has 6 rows.

How can I do this? In a non-multiindex table, I normally convert the index into a list and then use that list to sort the table. But here I don’t know how to do this.

EDIT: I also have a list with this

JavaScript

I could use this, couldn’t I?

Advertisement

Answer

IIUC, you can simply use loc.

Here is a dummy example:

JavaScript

reordering:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement