pandas.core.groupby.GroupBy.prod

Compute prod of group values.

return

Series or DataFrame Computed prod of values within each group.

Limitations

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff between staying in JIT-region with that function or going back to interpreter mode.

Examples

Compute prod of group values.
import pandas as pd
from numba import njit


@njit
def df_groupby_prod():
    df = pd.DataFrame({'A': [1, 2, 3, 1, 2, 3, 3, 3, 2],
                       'B': [0, 1, 5, 0, 2, 4, 3, 2, 3],
                       'C': [1, 2, 3, 4, 5, 6, 7, 8, 9]})
    out_df = df.groupby('A').prod()

    # Expect DataFrame of
    # {'B': [0, 6, 120], 'C': [4, 90, 1008} with index=[1, 2, 3]
    return out_df


print(df_groupby_prod())
$ python ./dataframe/groupby/dataframe_groupby_prod.py
     B     C
1    0     4
2    6    90
3  120  1008