There's more...

Whenever a solution involves melt, pivot_table, or pivot, you can be sure that there is an alternative method using stack and unstack. The trick is first to move the columns that are not currently being pivoted into the index:

>>> sensors.set_index(['Group', 'Property']) 
.stack()
.unstack('Property')
.rename_axis(['Group', 'Year'], axis='index')
.rename_axis(None, axis='columns')
.reset_index()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset