Complete the code to stack the columns of the DataFrame into a Series.
stacked = df.[1]()The stack() method compresses columns into a single Series with a MultiIndex.
Complete the code to unstack the last level of the index in the Series.
unstacked = stacked.[1]()The unstack() method pivots the innermost index level to columns.
Fix the error in the code to stack only the level named 'year' in the DataFrame.
stacked = df.[1](level='year')
The stack() method accepts a level argument to stack only that index level.
Fill both blanks to create a DataFrame from a stacked Series and then stack it back.
df_unstacked = stacked.[1]() df_stacked_again = df_unstacked.[2]()
First, unstack() converts the Series back to a DataFrame. Then stack() compresses it again.
Fill all three blanks to unstack the second level (level=1) of the MultiIndex and then stack only the 'year' level.
intermediate = stacked.[1](level=[2]) final = intermediate.[3](level='year')
unstack(level=1) pivots the second index level to columns, then stack(level='year') compresses the 'year' level.