Question:medium

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

The Correct Option is A

Solution and Explanation

Step 1: Idea:
Think of a sales sheet where the city Delhi sells the item Pen on two different days. If we want one row per city and one column per item, the cell (Delhi, Pen) has two numbers competing for one place. How a tool handles this clash is the whole difference.

Step 2: What pivot() does with the clash.
It has no rule to merge the two numbers. It stops with an error saying the index contains duplicate entries and cannot be reshaped.

Step 3: What pivot_table() does with the clash.
It applies an aggregation rule. With aggfunc='sum', the cell becomes the total of the two sales. With the default, it becomes their average. So no error occurs.

Step 4: Match with the options.
The only statement that describes combining the clashing values is option 1. Option 2 states the opposite of what is true. Option 3 describes merging tables, which is a different function. Option 4 describes fillna(0), which is a different function.

Step 5: Extra check.
A memory aid is that the word table in pivot_table points to a summary table, like a spreadsheet pivot table, which always totals or averages data. A plain pivot() only turns rows into columns without any totals. Also, pivot_table() can add margins and handle several value columns at once, which is more than a simple reshape.

Step 6: Conclusion.
Option 1 is correct. \[ \boxed{\text{It aggregates the values from rows with duplicate entries}} \]
Was this answer helpful?
0


Questions Asked in CUET (UG) exam