pyspark.pandas.groupby.GroupBy.mean

GroupBy.mean() → FrameLike[source]

Compute mean of groups, excluding missing values.

Returns
pyspark.pandas.Series or pyspark.pandas.DataFrame

Examples

>>> df = ps.DataFrame({'A': [1, 1, 2, 1, 2],
...                    'B': [np.nan, 2, 3, 4, 5],
...                    'C': [1, 2, 1, 1, 2]}, columns=['A', 'B', 'C'])

Groupby one column and return the mean of the remaining columns in each group.

>>> df.groupby('A').mean().sort_index()  
     B         C
A
1  3.0  1.333333
2  4.0  1.500000