@@ -1297,9 +1297,48 @@ def count(self):
1297
1297
@Appender (_doc_template )
1298
1298
def mean (self , * args , ** kwargs ):
1299
1299
"""
1300
- Compute mean of groups, excluding missing values
1300
+ Compute mean of groups, excluding missing values.
1301
1301
1302
- For multiple groupings, the result index will be a MultiIndex
1302
+ Returns
1303
+ -------
1304
+ pandas.Series or pandas.DataFrame
1305
+
1306
+ Examples
1307
+ --------
1308
+ >>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
1309
+ ... 'B': [np.nan, 2, 3, 4, 5],
1310
+ ... 'C': [1, 2, 1, 1, 2]}, columns=['A', 'B', 'C'])
1311
+
1312
+ Groupby one column and return the mean of the remaining columns in
1313
+ each group.
1314
+
1315
+ >>> df.groupby('A').mean()
1316
+ >>>
1317
+ B C
1318
+ A
1319
+ 1 3.0 1.333333
1320
+ 2 4.0 1.500000
1321
+
1322
+ Groupby two columns and return the mean of the remaining column.
1323
+
1324
+ >>> df.groupby(['A', 'B']).mean()
1325
+ >>>
1326
+ C
1327
+ A B
1328
+ 1 2.0 2
1329
+ 4.0 1
1330
+ 2 3.0 1
1331
+ 5.0 2
1332
+
1333
+ Groupby one column and return the mean of only particular column in
1334
+ the group.
1335
+
1336
+ >>> df.groupby('A')['B'].mean()
1337
+ >>>
1338
+ A
1339
+ 1 3.0
1340
+ 2 4.0
1341
+ Name: B, dtype: float64
1303
1342
"""
1304
1343
nv .validate_groupby_func ('mean' , args , kwargs , ['numeric_only' ])
1305
1344
try :
0 commit comments