Which of the following functions does Pandas provide to reshape the DataFrame?
Which of the following functions does Pandas provide to reshape the DataFrame?
Solution
pivot_table() is a real Pandas function that reshapes a DataFrame. It turns values from one column into new column headers and summarises the data with an aggregate function (the default is mean).
Example: df.pivot_table(index='Month', columns='City', values='Sales', aggfunc='sum')
Option 2: Pandas has no pivot.table(). The dot notation looks plausible, but pivot() is a function and has no table attribute.
Options 3 and 4: pivotable() and pivotting() do not exist in Pandas.
pivot() also reshapes but cannot aggregate, so it raises an error on duplicate index/column pairs. pivot_table() handles duplicates by aggregating them.
Related questions:
2025: 14 May Shift 1
2026: 31 May Shift 1
2026: 13 May Shift 2
2025: 14 May Shift 1
2025: 3 June Shift 2