A wide table with one column per month must become long, with month and value columns. Which call does that?
Correct answer
B. df.melt with id_vars, which turns the monthly columns into rows of key-value pairs
14 views
B. df.melt with id_vars, which turns the monthly columns into rows of key-value pairs
14 views
melt reshapes wide to long: id_vars stay fixed while value_vars become a variable column and a value column, so twelve monthly columns collapse into twelve rows per identifier. pivot performs the reverse, long to wide. stack is the MultiIndex equivalent of melt on columns, and unstack reverses it.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.