File tree 1 file changed +23
-0
lines changed 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1334,6 +1334,29 @@ def unique(self) -> Series:
1334
1334
1335
1335
1336
1336
class DataFrameGroupBy (GroupBy [DataFrame ]):
1337
+ groupby_agg_with_tuples_example = """
1338
+ Demonstrates using the `agg` method with a list of tuples for grouping and aggregation.
1339
+
1340
+ Consider a DataFrame `df`:
1341
+
1342
+ key | data
1343
+ ----|------
1344
+ 'a' | 0.5
1345
+ 'a' | -1.0
1346
+ 'b' | 2.0
1347
+ 'b' | -0.5
1348
+ 'a' | 1.2
1349
+
1350
+ Example: Applying multiple aggregations - mean and standard deviation
1351
+ df_result = df.groupby('key')['data'].agg([('mean_value', 'mean'), ('std_deviation', 'std')])
1352
+
1353
+ Using a list of tuples provides a concise way to apply multiple aggregations to the same column while controlling
1354
+ the output column names. This approach is especially handy when you need to calculate various statistics on
1355
+ the same data within each group.
1356
+
1357
+ :return: Example of using the `agg` method with a list of tuples for grouping and aggregation.
1358
+ :rtype: None
1359
+ """
1337
1360
_agg_examples_doc = dedent (
1338
1361
"""
1339
1362
Examples
You can’t perform that action at this time.
0 commit comments