Skip to content
Advertisement

setting columns in multiindex pandas

I have this pandas df which i imported from a csv:

JavaScript

Is it possible for everything on the left to be grouped under fresh and everything on the right of the dates to be under column spoil in multiindex format. Such as, there is one column which contains [apple, banana, orange]. I want to do this because later when i set the date as index there would be no confusion as both sides of the column have the same names.

Advertisement

Answer

JavaScript

output:

JavaScript

NB. if you want to set_index('dates') do it before this operation, this will be easier

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