NaN
values are skipped automatically. For example if we have the following table:
store reviewScore
0 a 4.0
1 b 3.0
2 a 3.0
3 a NaN
4 b 5.0
groupby
and find mean
for each group:
df.groupby('store', as_index = False).agg({'reviewScore': 'mean'})
what is equivalent to:
df.groupby('store', as_index = False).mean()
Output:
store reviewScore
0 a 3.5
1 b 4.0
To use arguments in aggregation functions you can utilize a lambda
function:
df.groupby('store', as_index = False).agg({'reviewScore': lambda x: x.mean(skipna=True)})
or
df.groupby('store', as_index = False).agg(lambda x: x.mean(skipna=True))
The result should be the same.