Melting pandas data frame with multiple variable names and multiple value names
问题 How can I melt a pandas data frame using multiple variable names and values? I have the following data frame that changes its shape in a for loop. In one of the for loop iterations, it looks like this: ID Cat Class_A Class_B Prob_A Prob_B 1 Veg 1 2 0.9 0.1 2 Veg 1 2 0.8 0.2 3 Meat 1 2 0.6 0.4 4 Meat 1 2 0.3 0.7 5 Veg 1 2 0.2 0.8 I need to melt it in such a way that it looks like this: ID Cat Class Prob 1 Veg 1 0.9 1 Veg 2 0.1 2 Veg 1 0.8 2 Veg 2 0.2 3 Meat 1 0.6 3 Meat 2 0.4 4 Meat 1 0.3 4