0
0
Pandasdata~10 mins

stack() and unstack() in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to stack the columns of the DataFrame into a Series.

Pandas
stacked = df.[1]()
Drag options to blanks, or click blank then click option'
Aunstack
Bmelt
Cpivot
Dstack
Attempts:
3 left
💡 Hint
Common Mistakes
Using unstack() instead of stack()
Using pivot() which reshapes differently
Using melt() which creates a different format
2fill in blank
medium

Complete the code to unstack the last level of the index in the Series.

Pandas
unstacked = s.[1]()
Drag options to blanks, or click blank then click option'
Apivot_table
Bstack
Cunstack
Dreset_index
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack() instead of unstack()
Using reset_index() which flattens the index
Using pivot_table() which aggregates data
3fill in blank
hard

Fix the error in the code to correctly unstack the level named 'month'.

Pandas
result = df.stack().[1]('month')
Drag options to blanks, or click blank then click option'
Aunstack
Bstack
Cpivot
Dmelt
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack() again causing deeper stacking
Using pivot() which requires different parameters
Using melt() which reshapes differently
4fill in blank
hard

Fill both blanks to stack the DataFrame while dropping NaN values.

Pandas
stacked = df.[1]([2]=True)
Drag options to blanks, or click blank then click option'
Astack
Bdropna
Cunstack
Dlevel
Attempts:
3 left
💡 Hint
Common Mistakes
Using unstack() instead of stack()
Using level=True which doesn't drop NaNs
Setting dropna=False explicitly
5fill in blank
hard

Fill all three blanks to stack the DataFrame and then unstack the outermost index level (level 0).

Pandas
result = df.[1]().[2]([3])
Drag options to blanks, or click blank then click option'
Astack
Bunstack
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-1' for innermost level instead of '0'
Using 'swaplevel' which only swaps levels
Omitting the level parameter