Complete the code to convert the DataFrame from long to wide format using pivot.
wide_df = long_df.pivot(index='[1]', columns='variable', values='value')
We use the 'id' column as the index to reshape the DataFrame from long to wide format.
Complete the code to reset the index of the wide DataFrame to turn the index back into a column.
wide_df = wide_df.[1]()reset_index() converts the index back into a regular column.
Fix the error in the code to pivot the DataFrame when there are duplicate entries for the index and columns combination.
wide_df = long_df.pivot_table(index='id', columns='[1]', values='value', aggfunc='mean')
When duplicates exist, pivot_table with aggfunc is used. The columns parameter should be the 'variable' column.
Fill both blanks to create a wide DataFrame with 'date' as index and 'category' as columns, aggregating values by sum.
wide_df = df.pivot_table(index='[1]', columns='[2]', values='sales', aggfunc='sum')
We use 'date' as index and 'category' as columns to reshape sales data, summing duplicates.
Fill all three blanks to create a dictionary of average scores by student and subject from a long DataFrame.
result = df.pivot_table(index='[1]', columns='[2]', values='[3]', aggfunc='mean').to_dict('index')
The dictionary keys are students, inner keys are subjects, and values are scores.