Complete the code to unpivot the DataFrame using pandas melt function.
import pandas as pd df = pd.DataFrame({ 'Name': ['Alice', 'Bob'], 'Math': [85, 90], 'Science': [88, 92] }) melted = pd.melt(df, id_vars=[1]) print(melted)
The id_vars parameter specifies columns to keep fixed. Here, 'Name' is the identifier column.
Complete the code to specify the variable name for the unpivoted columns.
melted = pd.melt(df, id_vars='Name', var_name=[1]) print(melted)
var_name with value_name.The var_name parameter sets the name of the new column that holds the original column names.
Fix the error in the code to correctly name the value column after melting.
melted = pd.melt(df, id_vars='Name', value_name=[1]) print(melted)
value_name as the original column name.value_name with var_name.The value_name parameter sets the name of the new column that holds the values from the original columns.
Fill both blanks to create a melted DataFrame with custom variable and value column names.
melted = pd.melt(df, id_vars=[1], var_name=[2]) print(melted)
Keep 'Name' as the identifier and rename the variable column to 'subject' for clarity.
Fill all three blanks to melt the DataFrame with custom id_vars, var_name, and value_name.
melted = pd.melt(df, id_vars=[1], var_name=[2], value_name=[3]) print(melted)
Use 'Name' as id_vars, rename variable column to 'subject', and value column to 'score' for clear data representation.