Skip to content

Tag: pandas

How to create a new index level with columns name in Pandas?

I would like to add a new level to the index of a dataframe, based on columns name. How can i do that ? Desired result I can build the multiindex with this but how can i create a new dataframe and map the data ? Answer You can use df.stack() Back to your code, you can try numpy.ravel to

Sort multiIndex table based on other table

I have a multiIndex data frame like this 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…

Order in dataframe generation

Could you explain to me why the Properties column was the third column and not the first one? As you can see I insert it as the first in pd.DataFrame, but when I do print(df), it appears as the third column. Answer Try using columns argument to assign the order of columns: This gives: