Python:Pandas .prod()
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.
Syntax
groupbyobject.prod(numeric_only=False, min_count=0)
Parameters:
numeric_only: IfTrue, non-numeric columns are excluded. IfFalse, 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 thanmin_count, the result for that group isNaN.
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 pddf = 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 Value20 A 2 101 A 3 52 B 4 23 B 5 34 C 6 45 C 9 26 D 10 11Value1 Value2KeyA 6 50B 20 6C 54 8D 10 11
Codebyte Example
This example computes the product of all prices and the product of all quantities within each category:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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