Skip to main contentSkip to solution

Which of the following functions does Pandas provide to reshape the DataFrame?

Solution

✅ Correct Option: 1

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question