October 2017
Intermediate to advanced
532 pages
16h 10m
English
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()
Read now
Unlock full access