Python:Pandas .prod()

SrikartikMateti's avatar
Published Oct 28, 2025
Contribute to Docs

The .prod() method produces a new Series or DataFrame with the product of the values in a GroupBy object.

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 Courses
    • With Professional Certification
    • Beginner Friendly.
      95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

groupbyobject.prod(numeric_only=False, min_count=0)

Parameters:

  • numeric_only: If True, non-numeric columns are excluded. If False, attempts to include all columns (non-numeric columns are ignored in computation).
  • min_count: If the number of valid (non-NA) entries in a group is less than min_count, the result for that group is NaN.

Return value:

Returns a DataFrame (or Series if applied on a SeriesGroupBy object) containing the product of each numeric column for each group.

Example

The following example produces a GroupBy object from a DataFrame and executes the .prod() method on it:

import pandas as pd
df = pd.DataFrame({
'Key' : ['A', 'A', 'B', 'B', 'C', 'C','D'],
'Value1' : [2, 3, 4, 5, 6, 9, 10],
'Value2' : [10, 5, 2, 3, 4, 2, 11]
})
print(df, end='\n\n')
group_prod = df.groupby('Key').prod()
print(group_prod)

This example produces the following output:

Key Value1 Value2
0 A 2 10
1 A 3 5
2 B 4 2
3 B 5 3
4 C 6 4
5 C 9 2
6 D 10 11
Value1 Value2
Key
A 6 50
B 20 6
C 54 8
D 10 11

Codebyte Example

This example computes the product of all prices and the product of all quantities within each category:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python:Pandas on Codecademy

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 Courses
    • With Professional Certification
    • Beginner Friendly.
      95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours