Question:

What does pivot_table( ) do in pandas that pivot( ) cannot?

Show Hint

pivot() fails on duplicate entries. pivot_table() aggregates them using aggfunc.
Updated On: Oct 1, 2026
  • It aggregates the values from rows with duplicate entries for the specified columns.
  • It does not allow duplicate data to be reshaped.
  • It merges multiple dataframes into one.
  • It converts NaN values to zero.
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Understanding the Concept:
Both pivot() and pivot_table() reshape a DataFrame. They turn the values of one column into new column headings. The key difference is what happens when the same pair of row and column labels appears more than once.

Step 2: How each one behaves.
pivot() only rearranges data. If the same pair of labels appears twice, it cannot decide which value to keep, so it raises a ValueError.
pivot_table() has an aggfunc argument, with default mean. It can combine the duplicate values using sum, mean, count, and so on. So it works on data with duplicates.

Step 3: Check option 1.
This says pivot_table() aggregates the values from rows with duplicate entries. That is exactly the extra power it has. So option 1 is correct.

Step 4: Check option 2.
This says it does not allow duplicates to be reshaped. It is the opposite. pivot() is the one that fails on duplicates. So option 2 is wrong.

Step 5: Check option 3.
Merging DataFrames is done with merge(), join() or concat(). It is not a pivot job. So option 3 is wrong.

Step 6: Check option 4.
Converting NaN to zero is done with fillna(0). pivot_table() has an optional fill_value argument, but it is not what separates it from pivot(), and it is not the main purpose. So option 4 is wrong.

Step 7: Final Answer:
pivot_table() can aggregate duplicate entries, which is option 1. \[ \boxed{\text{It aggregates the values from rows with duplicate entries}} \]
Was this answer helpful?
0
0