0
0
Data Analysis Pythondata~10 mins

Stack and unstack in Data Analysis Python - 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.

Data Analysis Python
stacked = df.[1]()
Drag options to blanks, or click blank then click option'
Aunstack
Bpivot
Cstack
Dmelt
Attempts:
3 left
💡 Hint
Common Mistakes
Using unstack instead of stack.
Using pivot which reshapes data differently.
Using melt which creates a long DataFrame, not a Series.
2fill in blank
medium

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

Data Analysis Python
unstacked = stacked.[1]()
Drag options to blanks, or click blank then click option'
Astack
Bunstack
Creset_index
Dpivot_table
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack instead of unstack.
Using reset_index which flattens the index but does not pivot.
Using pivot_table which requires specific arguments.
3fill in blank
hard

Fix the error in the code to stack only the level named 'year' in the DataFrame.

Data Analysis Python
stacked = df.[1](level='year')
Drag options to blanks, or click blank then click option'
Astack
Bmelt
Cpivot
Dunstack
Attempts:
3 left
💡 Hint
Common Mistakes
Using unstack with level argument which expands instead of compresses.
Using pivot which does not accept level argument.
Using melt which reshapes differently.
4fill in blank
hard

Fill both blanks to create a DataFrame from a stacked Series and then stack it back.

Data Analysis Python
df_unstacked = stacked.[1]()
df_stacked_again = df_unstacked.[2]()
Drag options to blanks, or click blank then click option'
Aunstack
Breset_index
Cstack
Dpivot
Attempts:
3 left
💡 Hint
Common Mistakes
Using reset_index which changes index structure but does not pivot.
Using pivot which requires specific arguments.
Reversing the order of stack and unstack.
5fill in blank
hard

Fill all three blanks to unstack the second level (level=1) of the MultiIndex and then stack only the 'year' level.

Data Analysis Python
intermediate = stacked.[1](level=[2])
final = intermediate.[3](level='year')
Drag options to blanks, or click blank then click option'
Aunstack
B1
Cstack
Dreset_index
Attempts:
3 left
💡 Hint
Common Mistakes
Using level=0 instead of level=1.
Using stack for the first blank instead of unstack.
Using reset_index or pivot inappropriately.