1. Home
  2. Data Science
  3. Pandas
  4. What does pd.pivot_table primarily produce in pandas?

Added 30 Nov -0001

What does pd.pivot_table primarily produce in pandas?

  1. A long-format frame holding exactly one row for every original observation
  2. A copy of the DataFrame sorted by its index
  3. A frame containing only the numeric columns
  4. A cross-tabulation with aggregated values at row and column intersections Correct answer

Correct answer

D. A cross-tabulation with aggregated values at row and column intersections

16 views

MCQSEXAM

Explanation

pivot_table groups by one field for rows and another for columns, then aggregates the values at each intersection, defaulting to the mean. It is essentially groupby plus a reshape, and the inverse operation that melts a wide table back into long form is melt. Passing aggfunc="sum" or a list of functions controls the summary, and margins=True adds row and column totals.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs