1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
U
¬ý°dZAã    @stdZddlmZddlZddlmZmZddlZddlm    Z    ddl
m Z m Z m Z mZmZmZmZmZmZmZmZmZmZddlZddlZddlmZddlmZmZdd    l m!Z!ddl"m#m$Z%dd
l&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5dd l6m7Z8dd l9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLddlMmNZNmOZOddlPmQZQmRZRddlSmTZTddlUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^m_Z_ddl`mambZcddldmeZeddlfmgZgddlhmiZimjZjmkZkddllmmZmddlnmoZompZpddlqmrZrmsZsmtZtmuZumvZvddlwmxZxddlymzZzddl{m|Z|ddl}m~Z~mZe ršdd l€mZm‚Z‚mƒZƒd!Z„d"d#d$d%œZ…d&Z†d'Z‡d(Zˆd)Z‰eGd*d+„d+e^ƒƒZŠee ee e e ge fee e ge fee e ffZ‹Gd,d-„d-e^e_e0eoƒZŒed.egd/ZGd0d1„d1eŒe0ƒZŽe@eŽƒdAd3d4d5d6d7d1d8œd9d:„ƒZd;d<d=d>œd?d@„ZdS)Ba
Provide the groupby split-apply-combine paradigm. Define the GroupBy
class providing the base-class of operations.
 
The SeriesGroupBy and DataFrameGroupBy sub-class
(defined in pandas.core.groupby.generic)
expose these user-facing objects to provide specific functionality.
é)Ú annotationsN)ÚpartialÚwraps)Údedent) Ú TYPE_CHECKINGÚCallableÚHashableÚIterableÚIteratorÚListÚLiteralÚMappingÚSequenceÚTypeVarÚUnionÚcastÚfinal)Úoption_context)Ú    TimestampÚlib)Úrank_1d)ÚNA) Ú AnyArrayLikeÚ    ArrayLikeÚAxisÚAxisIntÚDtypeObjÚ FillnaOptionsÚ
IndexLabelÚNDFrameTÚPositionalIndexerÚ RandomStateÚScalarÚTÚnpt)Úfunction)ÚAbstractMethodErrorÚ    DataError)ÚAppenderÚ SubstitutionÚcache_readonlyÚdoc)Úensure_dtype_can_hold_na)    Ú is_bool_dtypeÚis_float_dtypeÚ is_hashableÚ
is_integerÚis_integer_dtypeÚis_numeric_dtypeÚis_object_dtypeÚ    is_scalarÚneeds_i8_conversion)ÚisnaÚnotna)Ú
algorithmsÚsample)Úexecutor)ÚBaseMaskedArrayÚ BooleanArrayÚ CategoricalÚ DatetimeArrayÚExtensionArrayÚ FloatingArrayÚTimedeltaArray)Ú PandasObjectÚSelectionMixin)Ú    DataFrame)ÚNDFrame)ÚbaseÚnumba_Úops)Ú get_grouper)ÚGroupByIndexingMixinÚGroupByNthSelector)ÚCategoricalIndexÚIndexÚ
MultiIndexÚ
RangeIndexÚ default_index)Úensure_block_shape)ÚSeries)Úget_group_index_sorter)Úget_jit_argumentsÚmaybe_use_numba)ÚExpandingGroupbyÚExponentialMovingWindowGroupbyÚRollingGroupbyzÍ
        See Also
        --------
        Series.%(name)s : Apply a function %(name)s to a Series.
        DataFrame.%(name)s : Apply a function %(name)s
            to each row or column of a DataFrame.
aS
    Apply function ``func`` group-wise and combine the results together.
 
    The function passed to ``apply`` must take a {input} as its first
    argument and return a DataFrame, Series or scalar. ``apply`` will
    then take care of combining the results back together into a single
    dataframe or series. ``apply`` is therefore a highly flexible
    grouping method.
 
    While ``apply`` is a very flexible method, its downside is that
    using it can be quite a bit slower than using more specific methods
    like ``agg`` or ``transform``. Pandas offers a wide range of method that will
    be much faster than using ``apply`` for their specific purposes, so try to
    use them before reaching for ``apply``.
 
    Parameters
    ----------
    func : callable
        A callable that takes a {input} as its first argument, and
        returns a dataframe, a series or a scalar. In addition the
        callable may take positional and keyword arguments.
    args, kwargs : tuple and dict
        Optional positional and keyword arguments to pass to ``func``.
 
    Returns
    -------
    Series or DataFrame
 
    See Also
    --------
    pipe : Apply function to the full GroupBy object instead of to each
        group.
    aggregate : Apply aggregate function to the GroupBy object.
    transform : Apply function column-by-column to the GroupBy object.
    Series.apply : Apply a function to a Series.
    DataFrame.apply : Apply a function to each row or column of a DataFrame.
 
    Notes
    -----
 
    .. versionchanged:: 1.3.0
 
        The resulting dtype will reflect the return value of the passed ``func``,
        see the examples below.
 
    Functions that mutate the passed object can produce unexpected
    behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
    for more details.
 
    Examples
    --------
    {examples}
    a%
    >>> df = pd.DataFrame({'A': 'a a b'.split(),
    ...                    'B': [1,2,3],
    ...                    'C': [4,6,5]})
    >>> g1 = df.groupby('A', group_keys=False)
    >>> g2 = df.groupby('A', group_keys=True)
 
    Notice that ``g1`` and ``g2`` have two groups, ``a`` and ``b``, and only
    differ in their ``group_keys`` argument. Calling `apply` in various ways,
    we can get different grouping results:
 
    Example 1: below the function passed to `apply` takes a DataFrame as
    its argument and returns a DataFrame. `apply` combines the result for
    each group together into a new DataFrame:
 
    >>> g1[['B', 'C']].apply(lambda x: x / x.sum())
              B    C
    0  0.333333  0.4
    1  0.666667  0.6
    2  1.000000  1.0
 
    In the above, the groups are not part of the index. We can have them included
    by using ``g2`` where ``group_keys=True``:
 
    >>> g2[['B', 'C']].apply(lambda x: x / x.sum())
                B    C
    A
    a 0  0.333333  0.4
      1  0.666667  0.6
    b 2  1.000000  1.0
 
    Example 2: The function passed to `apply` takes a DataFrame as
    its argument and returns a Series.  `apply` combines the result for
    each group together into a new DataFrame.
 
    .. versionchanged:: 1.3.0
 
        The resulting dtype will reflect the return value of the passed ``func``.
 
    >>> g1[['B', 'C']].apply(lambda x: x.astype(float).max() - x.min())
         B    C
    A
    a  1.0  2.0
    b  0.0  0.0
 
    >>> g2[['B', 'C']].apply(lambda x: x.astype(float).max() - x.min())
         B    C
    A
    a  1.0  2.0
    b  0.0  0.0
 
    The ``group_keys`` argument has no effect here because the result is not
    like-indexed (i.e. :ref:`a transform <groupby.transform>`) when compared
    to the input.
 
    Example 3: The function passed to `apply` takes a DataFrame as
    its argument and returns a scalar. `apply` combines the result for
    each group together into a Series, including setting the index as
    appropriate:
 
    >>> g1.apply(lambda x: x.C.max() - x.B.min())
    A
    a    5
    b    2
    dtype: int64a‚
    >>> s = pd.Series([0, 1, 2], index='a a b'.split())
    >>> g1 = s.groupby(s.index, group_keys=False)
    >>> g2 = s.groupby(s.index, group_keys=True)
 
    From ``s`` above we can see that ``g`` has two groups, ``a`` and ``b``.
    Notice that ``g1`` have ``g2`` have two groups, ``a`` and ``b``, and only
    differ in their ``group_keys`` argument. Calling `apply` in various ways,
    we can get different grouping results:
 
    Example 1: The function passed to `apply` takes a Series as
    its argument and returns a Series.  `apply` combines the result for
    each group together into a new Series.
 
    .. versionchanged:: 1.3.0
 
        The resulting dtype will reflect the return value of the passed ``func``.
 
    >>> g1.apply(lambda x: x*2 if x.name == 'a' else x/2)
    a    0.0
    a    2.0
    b    1.0
    dtype: float64
 
    In the above, the groups are not part of the index. We can have them included
    by using ``g2`` where ``group_keys=True``:
 
    >>> g2.apply(lambda x: x*2 if x.name == 'a' else x/2)
    a  a    0.0
       a    2.0
    b  b    1.0
    dtype: float64
 
    Example 2: The function passed to `apply` takes a Series as
    its argument and returns a scalar. `apply` combines the result for
    each group together into a Series, including setting the index as
    appropriate:
 
    >>> g1.apply(lambda x: x.max() - x.min())
    a    1
    b    0
    dtype: int64
 
    The ``group_keys`` argument has no effect here because the result is not
    like-indexed (i.e. :ref:`a transform <groupby.transform>`) when compared
    to the input.
 
    >>> g2.apply(lambda x: x.max() - x.min())
    a    1
    b    0
    dtype: int64)ÚtemplateÚdataframe_examplesZseries_examplesaã
Compute {fname} of group values.
 
Parameters
----------
numeric_only : bool, default {no}
    Include only float, int, boolean columns.
 
    .. versionchanged:: 2.0.0
 
        numeric_only no longer accepts ``None``.
 
min_count : int, default {mc}
    The required number of valid values to perform the operation. If fewer
    than ``min_count`` non-NA values are present the result will be NA.
 
Returns
-------
Series or DataFrame
    Computed {fname} of values within each group.
aF
Apply a ``func`` with arguments to this %(klass)s object and return its result.
 
Use `.pipe` when you want to improve readability by chaining together
functions that expect Series, DataFrames, GroupBy or Resampler objects.
Instead of writing
 
>>> h(g(f(df.groupby('group')), arg1=a), arg2=b, arg3=c)  # doctest: +SKIP
 
You can write
 
>>> (df.groupby('group')
...    .pipe(f)
...    .pipe(g, arg1=a)
...    .pipe(h, arg2=b, arg3=c))  # doctest: +SKIP
 
which is much more readable.
 
Parameters
----------
func : callable or tuple of (callable, str)
    Function to apply to this %(klass)s object or, alternatively,
    a `(callable, data_keyword)` tuple where `data_keyword` is a
    string indicating the keyword of `callable` that expects the
    %(klass)s object.
args : iterable, optional
       Positional arguments passed into `func`.
kwargs : dict, optional
         A dictionary of keyword arguments passed into `func`.
 
Returns
-------
the return type of `func`.
 
See Also
--------
Series.pipe : Apply a function with arguments to a series.
DataFrame.pipe: Apply a function with arguments to a dataframe.
apply : Apply function to each group instead of to the
    full %(klass)s object.
 
Notes
-----
See more `here
<https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#piping-function-calls>`_
 
Examples
--------
%(examples)s
a
Call function producing a same-indexed %(klass)s on each group.
 
Returns a %(klass)s having the same indexes as the original object
filled with the transformed values.
 
Parameters
----------
f : function, str
    Function to apply to each group. See the Notes section below for requirements.
 
    Accepted inputs are:
 
    - String
    - Python function
    - Numba JIT function with ``engine='numba'`` specified.
 
    Only passing a single function is supported with this engine.
    If the ``'numba'`` engine is chosen, the function must be
    a user defined function with ``values`` and ``index`` as the
    first and second arguments respectively in the function signature.
    Each group's index will be passed to the user defined function
    and optionally available for use.
 
    If a string is chosen, then it needs to be the name
    of the groupby method you want to use.
 
    .. versionchanged:: 1.1.0
*args
    Positional arguments to pass to func.
engine : str, default None
    * ``'cython'`` : Runs the function through C-extensions from cython.
    * ``'numba'`` : Runs the function through JIT compiled code from numba.
    * ``None`` : Defaults to ``'cython'`` or the global setting ``compute.use_numba``
 
    .. versionadded:: 1.1.0
engine_kwargs : dict, default None
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
      and ``parallel`` dictionary keys. The values must either be ``True`` or
      ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
      ``{'nopython': True, 'nogil': False, 'parallel': False}`` and will be
      applied to the function
 
    .. versionadded:: 1.1.0
**kwargs
    Keyword arguments to be passed into func.
 
Returns
-------
%(klass)s
 
See Also
--------
%(klass)s.groupby.apply : Apply function ``func`` group-wise and combine
    the results together.
%(klass)s.groupby.aggregate : Aggregate using one or more
    operations over the specified axis.
%(klass)s.transform : Call ``func`` on self producing a %(klass)s with the
    same axis shape as self.
 
Notes
-----
Each group is endowed the attribute 'name' in case you need to know
which group you are working on.
 
The current implementation imposes three requirements on f:
 
* f must return a value that either has the same shape as the input
  subframe or can be broadcast to the shape of the input subframe.
  For example, if `f` returns a scalar it will be broadcast to have the
  same shape as the input subframe.
* if this is a DataFrame, f must support application column-by-column
  in the subframe. If f also supports application to the entire subframe,
  then a fast path is used starting from the second chunk.
* f must not mutate groups. Mutation is not supported and may
  produce unexpected results. See :ref:`gotchas.udf-mutation` for more details.
 
When using ``engine='numba'``, there will be no "fall back" behavior internally.
The group data and group index will be passed as numpy arrays to the JITed
user defined function, and no alternative execution attempts will be tried.
 
.. versionchanged:: 1.3.0
 
    The resulting dtype will reflect the return value of the passed ``func``,
    see the examples below.
 
.. versionchanged:: 2.0.0
 
    When using ``.transform`` on a grouped DataFrame and the transformation function
    returns a DataFrame, pandas now aligns the result's index
    with the input's index. You can call ``.to_numpy()`` on the
    result of the transformation function to avoid alignment.
 
Examples
--------
%(example)sa=
Aggregate using one or more operations over the specified axis.
 
Parameters
----------
func : function, str, list, dict or None
    Function to use for aggregating the data. If a function, must either
    work when passed a {klass} or when passed to {klass}.apply.
 
    Accepted combinations are:
 
    - function
    - string function name
    - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
    - dict of axis labels -> functions, function names or list of such.
    - None, in which case ``**kwargs`` are used with Named Aggregation. Here the
      output has one column for each element in ``**kwargs``. The name of the
      column is keyword, whereas the value determines the aggregation used to compute
      the values in the column.
 
    Can also accept a Numba JIT function with
    ``engine='numba'`` specified. Only passing a single function is supported
    with this engine.
 
    If the ``'numba'`` engine is chosen, the function must be
    a user defined function with ``values`` and ``index`` as the
    first and second arguments respectively in the function signature.
    Each group's index will be passed to the user defined function
    and optionally available for use.
 
    .. versionchanged:: 1.1.0
*args
    Positional arguments to pass to func.
engine : str, default None
    * ``'cython'`` : Runs the function through C-extensions from cython.
    * ``'numba'`` : Runs the function through JIT compiled code from numba.
    * ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
 
    .. versionadded:: 1.1.0
engine_kwargs : dict, default None
    * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
    * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
      and ``parallel`` dictionary keys. The values must either be ``True`` or
      ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
      ``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
      applied to the function
 
    .. versionadded:: 1.1.0
**kwargs
    * If ``func`` is None, ``**kwargs`` are used to define the output names and
      aggregations via Named Aggregation. See ``func`` entry.
    * Otherwise, keyword arguments to be passed into func.
 
Returns
-------
{klass}
 
See Also
--------
{klass}.groupby.apply : Apply function func group-wise
    and combine the results together.
{klass}.groupby.transform : Transforms the Series on each group
    based on the given function.
{klass}.aggregate : Aggregate using one or more
    operations over the specified axis.
 
Notes
-----
When using ``engine='numba'``, there will be no "fall back" behavior internally.
The group data and group index will be passed as numpy arrays to the JITed
user defined function, and no alternative execution attempts will be tried.
 
Functions that mutate the passed object can produce unexpected
behavior or errors and are not supported. See :ref:`gotchas.udf-mutation`
for more details.
 
.. versionchanged:: 1.3.0
 
    The resulting dtype will reflect the return value of the passed ``func``,
    see the examples below.
{examples}c@s6eZdZdZdddœdd„Zdd„Zd    d
œd d „Zd S)Ú GroupByPlotzE
    Class implementing the .plot attribute for groupby objects.
    ÚGroupByÚNone)ÚgroupbyÚreturncCs
||_dS©N)Ú_groupby)Úselfr^©rcúRd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/groupby/groupby.pyÚ__init__GszGroupByPlot.__init__cs ‡‡fdd„}d|_|j |¡S)Ncs |jˆˆŽSr`)Úplot©rb©ÚargsÚkwargsrcrdÚfKszGroupByPlot.__call__.<locals>.frf)Ú__name__raÚapply)rbrirjrkrcrhrdÚ__call__JszGroupByPlot.__call__Ústr©Únamecs‡‡fdd„}|S)Ncs‡‡‡fdd„}ˆj |¡S)Ncst|jˆƒˆˆŽSr`)Úgetattrrfrg)rirjrqrcrdrkSsz0GroupByPlot.__getattr__.<locals>.attr.<locals>.f)rarm)rirjrk©rqrbrhrdÚattrRsz%GroupByPlot.__getattr__.<locals>.attrrc)rbrqrtrcrsrdÚ __getattr__QszGroupByPlot.__getattr__N)rlÚ
__module__Ú __qualname__Ú__doc__rernrurcrcrcrdr[Asr[c @sLeZdZUejddddddddd    d
d h BZd ed<d ed<dZded<dZded<ded<eddœdd„ƒZ    eddœdd„ƒZ
ee ddœdd„ƒƒZ ee ddœdd„ƒƒZ ee ddœdd „ƒƒZed!d"„ƒZed#d$„ƒZeed%d&„ƒƒZed'dœd(d)„ƒZed*ed+ƒd,eeƒd-d.d/œd0d1„ƒƒZed8d2dœd3d4„ƒZed5dœd6d7„ƒZdS)9Ú BaseGroupByÚas_indexÚaxisÚdropnaÚ
exclusionsÚgrouperÚ
group_keysÚkeysÚlevelÚobjÚobservedÚsortrúops.BaseGrouperNú_KeysArgType | NoneúIndexLabel | NoneÚboolÚint©r_cCs
t|jƒSr`)ÚlenÚgroupsrgrcrcrdÚ__len__yszBaseGroupBy.__len__rocCs
t |¡Sr`)ÚobjectÚ__repr__rgrcrcrdr}szBaseGroupBy.__repr__zdict[Hashable, np.ndarray]cCs|jjS)z4
        Dict {group name -> group labels}.
        )r~rŒrgrcrcrdrŒ‚szBaseGroupBy.groupscCs|jjSr`)r~ÚngroupsrgrcrcrdrŠszBaseGroupBy.ngroupsz$dict[Hashable, npt.NDArray[np.intp]]cCs|jjS)z5
        Dict {group name -> group indices}.
        )r~Úindicesrgrcrcrdr‘szBaseGroupBy.indicesc
s
dd„‰t|ƒdkrgStˆjƒdkr6ttˆjƒƒ}nd}|d}t|tƒrÞt|tƒsbd}t|ƒ‚t|ƒt|ƒks¸z‡fdd„|DƒWStk
r¶}zd}t|ƒ|‚W5d}~XYnX‡fd    d„|Dƒ‰‡fd
d „|Dƒ}nˆ|ƒ‰‡fd d „|Dƒ}‡fd d„|DƒS)zd
        Safe get multiple indices, translate keys for
        datelike to underlying repr.
        cSs4t|tjƒrdd„St|tjƒr(dd„Sdd„SdS)NcSst|ƒSr`)r©ÚkeyrcrcrdÚ<lambda>¢ózABaseGroupBy._get_indices.<locals>.get_converter.<locals>.<lambda>cSs
t|ƒjSr`)rZasm8r’rcrcrdr”¤r•cSs|Sr`rcr’rcrcrdr”¦r•)Ú
isinstanceÚdatetimeÚnpZ
datetime64)ÚsrcrcrdÚ get_converteržs
  z/BaseGroupBy._get_indices.<locals>.get_converterrNz<must supply a tuple to get_group with multiple grouping keyscsg|]}ˆj|‘qSrc)r‘©Ú.0rqrgrcrdÚ
<listcomp>¸sz,BaseGroupBy._get_indices.<locals>.<listcomp>zHmust supply a same-length tuple to get_group with multiple grouping keyscsg|] }ˆ|ƒ‘qSrcrc)rœr™)ršrcrdrÁsc3s&|]}tdd„tˆ|ƒDƒƒVqdS)css|]\}}||ƒVqdSr`rc)rœrkÚnrcrcrdÚ    <genexpr>Âsz5BaseGroupBy._get_indices.<locals>.<genexpr>.<genexpr>N)ÚtupleÚzipr›)Ú
convertersrcrdrŸÂsz+BaseGroupBy._get_indices.<locals>.<genexpr>c3s|]}ˆ|ƒVqdSr`rcr›)Ú    converterrcrdrŸÆscsg|]}ˆj |g¡‘qSrc)r‘Úgetr›rgrcrdrÈs)r‹r‘ÚnextÚiterr–r Ú
ValueErrorÚKeyError)rbÚnamesZ index_sampleZ name_sampleÚmsgÚerrrc)r£r¢ršrbrdÚ _get_indices—s.
 
 
ÿzBaseGroupBy._get_indicescCs| |g¡dS)zQ
        Safe get index, translate keys for datelike to underlying repr.
        r)r¬)rbrqrcrcrdÚ
_get_indexÊszBaseGroupBy._get_indexcCs>t|jtƒr|jS|jdk    r8t|jƒr2|j|jS|jS|jSr`)r–r‚rRÚ
_selectionr/Ú_obj_with_exclusionsrgrcrcrdÚ _selected_objÑs 
 
 zBaseGroupBy._selected_objzset[str]cCs
|j ¡Sr`)r‚Ú_dir_additionsrgrcrcrdr±æszBaseGroupBy._dir_additionsr\a†        >>> df = pd.DataFrame({'A': 'a b a b'.split(), 'B': [1, 2, 3, 4]})
        >>> df
           A  B
        0  a  1
        1  b  2
        2  a  3
        3  b  4
 
        To get the difference between each groups maximum and minimum value in one
        pass, you can do
 
        >>> df.groupby('A').pipe(lambda x: x.max() - x.min())
           B
        A
        a  2
        b  2)ÚklassÚexamplesz/Callable[..., T] | tuple[Callable[..., T], str]r#)Úfuncr_cOstj||f|ž|ŽSr`)ÚcomÚpipe)rbr´rirjrcrcrdr¶êszBaseGroupBy.pipeúDataFrame | SeriescCs8|dkr|j}| |¡}t|ƒs(t|ƒ‚|j||jdS)a©
        Construct DataFrame from group with provided name.
 
        Parameters
        ----------
        name : object
            The name of the group to get as a DataFrame.
        obj : DataFrame, default None
            The DataFrame to take the DataFrame out of.  If
            it is None, the object groupby was called on will
            be used.
 
        Returns
        -------
        same type as obj
        N©r{)r°r­r‹r¨Z_take_with_is_copyr{)rbrqr‚ZindsrcrcrdÚ    get_group    s 
zBaseGroupBy.get_groupz#Iterator[tuple[Hashable, NDFrameT]]cCsB|j}|jj|j|jd}t|tƒr>t|ƒdkr>dd„|Dƒ}|S)z›
        Groupby iterator.
 
        Returns
        -------
        Generator yielding sequence of (name, subsetted object)
        for each group
        r¸écss|]\}}|f|fVqdSr`rc)rœr“ÚgrouprcrcrdrŸ2sz'BaseGroupBy.__iter__.<locals>.<genexpr>)r€r~Ú get_iteratorr°r{r–Úlistr‹)rbr€ÚresultrcrcrdÚ__iter__$s
 
zBaseGroupBy.__iter__)N)rlrvrwrBZ _hidden_attrsÚ__annotations__r€rrrrÚpropertyrŒrr‘r¬r­r*r°r±r)rr(Ú_pipe_templater¶r¹r¿rcrcrcrdrydsh
õ  
2
 ÿþryÚOutputFrameOrSeries)Úboundc@s^eZdZUdZded<ded<edd
d d d ddd dddddddœ dd„ƒZddœdd„Zeddœdd„ƒZddœdd„Z    eddddœd d!„ƒZ
ed"d"d#œd$d%„ƒZ ed&d'd#œd(d)„ƒZ d*d&d#œd+d,„Z ed
d
d#œd-d.„ƒZedd&d/d0œd1d2„ƒZdd3ddd4œd5d6„Zed'd7œd8d9„ƒZd:d;d<œd=d>„Zedd?œd@dA„ƒZedd?œdBdC„ƒZeedDjdEedFdGƒd
dœdHdI„ƒZedd:dJdKddd
dLœdMdN„ƒZedddPdd:dQœdRdS„ƒZdTdPd:dTdUœdVdW„Zeddd:ddPdXœdYdZ„ƒZdddd[d\œd]d^„Zeddd_œd`da„ƒZed
d
d#œdbdc„ƒZeddde„ƒZ ed    ddfdgœdhdi„ƒZ!ee"d:dœdjdk„ƒƒZ#edlddmœdndo„ƒZ$ee%dpdee&ƒd
ddqœdrds„ƒƒƒZ'ee%dpdee&ƒd ddqœdtdu„ƒƒƒZ(ee%dpdee&ƒd
dœdvdw„ƒƒƒZ)ee%dpde%e&dxd ddd;dzœd{d|„ƒƒƒZ*ed dd}œd~d„ƒZ+ee%dpdee&ƒddPdd;dd‚œdƒd„„ƒƒƒZ,ee%dpdee&ƒddPdd;dd‚œd…d†„ƒƒƒZ-edd‡dddddJdˆœd‰dŠ„ƒZ.eddPdd‹œdŒd„ƒZ/ee%dpdee&ƒdJdœdŽd„ƒƒƒZ0ee1e2dd    dd‘dddPdd;d’œd“d”„ƒƒZ3ee1e2d•d    dd‘dddPd–œd—d˜„ƒƒZ4ee1e2d™d    dOd‘dddPdd;d’œdšd›„ƒƒZ5ee1e2dœd    dOd‘dddPdd;d’œddž„ƒƒZ6edddPd–œdŸd „ƒZ7edddPd–œd¡d¢„ƒZ8ed'dœd£d¤„ƒZ9e1e:j;ƒdd
dœd¥d¦„ƒZ;ed§d¨„ƒZ<ed©dœdªd«„ƒZ=ee%dpdee&ƒd¬dœd­d®„ƒƒƒZ>ee%dpdee&ƒd¯dœd°d±„ƒƒƒZ?edd²d³œd´dµ„ƒZ@ee%dpddd¶d·„ƒƒZAee%dpddd¸d¹„ƒƒZBee"e%dpde%e&dxdºdœd»d¼„ƒƒƒƒZCdd½d¾d
d¿œdÀdÁ„ZDeddÄdddŜdÆdDŽƒZEee%dpddddȜdÉdʄƒƒZFee%dpddddȜdËd̄ƒƒZGee%dpde%e&dxd ddddd[d
dϜdÐdфƒƒƒZHee%dpdee&ƒd!d d
dҜdÓdԄƒƒƒZIee%dpdee&ƒd"d d
dҜdÕdքƒƒƒZJee%dpdee&ƒd#d[dd
dלdØdلƒƒƒZKee%dpdee&ƒd$d[dd
dלdÚdۄƒƒƒZLed%d:dÝddddޜdßdà„ƒZMee%dpdd&dPd dáœdâd㄃ƒZNee%dpdee&ƒd'dPd[d
däœdåd愃ƒƒZOee%dpdee&ƒd(dPdèd déœdêd넃ƒƒZPee%dpde%e&dxd)dPd
díœdîdƒƒZQee%dpde%e&dxd*dPd
díœdðdñ„ƒƒƒZRedòd
dóœdôdõ„ƒZSeeTjUdfd"död/d"d÷œdødù„ƒZVed+dúdûddüdýdþœdÿd„ƒZWdS(,r\a™
    Class for grouping and aggregating relational data.
 
    See aggregate, transform, and apply functions on this object.
 
    It's easiest to use obj.groupby(...) to use GroupBy, but you can also do:
 
    ::
 
        grouped = groupby(obj, ...)
 
    Parameters
    ----------
    obj : pandas object
    axis : int, default 0
    level : int, default None
        Level of MultiIndex
    groupings : list of Grouping objects
        Most users should ignore this
    exclusions : array-like, optional
        List of columns to exclude
    name : str
        Most users should ignore this
 
    Returns
    -------
    **Attributes**
    groups : dict
        {group name -> group labels}
    len(grouped) : int
        Number of groups
 
    Notes
    -----
    After grouping, see aggregate, apply, and transform functions. Here are
    some other brief notes about usage. When grouping by multiple groups, the
    result index will be a MultiIndex (hierarchical) by default.
 
    Iteration produces (key, group) tuples, i.e. chunking the data by group. So
    you can write code like:
 
    ::
 
        grouped = obj.groupby(keys, axis=axis)
        for key, group in grouped:
            # do something with the data
 
    Function calls on GroupBy, if not specially implemented, "dispatch" to the
    grouped data. So if you group a DataFrame and wish to invoke the std()
    method on each group, you can simply do:
 
    ::
 
        df.groupby(mapper).std()
 
    rather than
 
    ::
 
        df.groupby(mapper).aggregate(np.std)
 
    You can pass arguments to these "wrapped" functions, too.
 
    See the online documentation for full exposition on these topics and much
    more
    r…r~rˆrzNrTFrr†rr‡úops.BaseGrouper | Nonezfrozenset[Hashable] | Noner]) r‚r€r{rr~r}Ú    selectionrzr„rrƒr|r_c     Cs°||_t|tƒstt|ƒƒ‚||_|s6|dkr6tdƒ‚||_||_|    |_    |
|_
| |_ | |_ |dkr€t |||||    | |j d\}}}||_| |¡|_||_|r¤t|ƒntƒ|_dS)Nrz$as_index=False only valid for axis=0)r{rr„rƒr|)r®r–rEÚAssertionErrorÚtyperr§rzr€r„rrƒr|rIr‚Z_get_axis_numberr{r~Ú    frozensetr}) rbr‚r€r{rr~r}rÆrzr„rrƒr|rcrcrdres4ù
 zGroupBy.__init__ro)rtcCsH||jkrt ||¡S||jkr(||Stdt|ƒj›d|›dƒ‚dS)Nú'z' object has no attribute ')Z_internal_names_setrŽÚ__getattribute__r‚ÚAttributeErrorrÈrl)rbrtrcrcrdru²s
 
ÿzGroupBy.__getattr__rpcs²tt|jƒ|ƒ‰t ˆ¡}d|jkrNˆ dd¡dksDˆ d¡tjkrN|j    ˆd<‡‡‡fdd„}||_
|t j krx|  |¡S|t jk}|j||j|| d}|jjr®|r®| |¡}|S)z<Compute the result of an operation by using GroupBy's apply.r{Ncsˆ|fˆžˆŽSr`rc©Úx©rirkrjrcrdÚcurriedÈsz&GroupBy._op_via_apply.<locals>.curried)Ú is_transformÚnot_indexed_same)rrrÈr¯ÚinspectÚ    signatureÚ
parametersr¤rZ
no_defaultr{rlrFZplotting_methodsrmÚtransformation_kernelsÚ_python_apply_generalr~Úhas_dropped_naÚ_set_result_index_ordered)rbrqrirjÚsigrÐrÑr¾rcrÏrdÚ _op_via_apply¼s&
 
 
 
 
 
ü 
zGroupBy._op_via_applyzIterable[Series]rŠcCs t|ƒ‚dSr`©r&rgrcrcrdÚ_iterate_slicesåszGroupBy._iterate_slices)rÒrÑcCsVddlm}|jrn|sn|jrL|jj}|jj}|jj}|||j|||dd}n t    t
t |ƒƒƒ}    |||j|    d}n¬|s |||jd}|j   |j¡}
|jr²|jjd} | dk} |
| }
|
jrø|j|j |
¡søt |
j¡} |j | ¡\}}|j||jd}n|j|
|jdd}n|||jd}|jjd    kr0|jjn|j}t|tƒrR|dk    rR||_|S)
Nr)ÚconcatF)r{r€Úlevelsr©r„)r{r€r¸éÿÿÿÿ©r{Úcopyrº) Zpandas.core.reshape.concatrÞrrzr~Ú result_indexrßr©r{r½Úranger‹r°Ú    _get_axisr|Ú
group_infoZhas_duplicatesÚaxesÚequalsr8Zunique1dÚ_valuesÚindexZget_indexer_non_uniqueÚtakeÚreindexr‚Úndimrqr®r–rR)rbÚvaluesrÒrÑrÞrZ group_levelsZ group_namesr¾r€ZaxÚlabelsÚmaskÚtargetÚindexerÚ_rqrcrcrdÚ_concat_objectsësB 
ú   zGroupBy._concat_objectsrÃ)r¾r_cCs˜|j |j¡}|jjr4|jjs4|j||jdd}|St|j ¡ƒ}|j||jdd}|j    |jd}|jjr‚|j
t t |ƒƒ|jd}|j||jdd}|S)NFrár¸) r‚rår{r~Z is_monotonicrØÚset_axisrMÚ result_ilocsÚ
sort_indexrìrOr‹)rbr¾Zobj_axisZoriginal_positionsrcrcrdrÙ)sz!GroupBy._set_result_index_orderedzSeries | DataFramerDcCsrt|tƒr| ¡}|j}tt|jjƒt|j ¡ƒtdd„|jj    DƒƒƒD]$\}}}|rH||krH| 
d||¡qH|S)NcSsg|]
}|j‘qSrc)Úin_axis)rœÚgrprcrcrdrMsz2GroupBy._insert_inaxis_grouper.<locals>.<listcomp>r) r–rRÚto_frameÚcolumnsr¡Úreversedr~r©Zget_group_levelsÚ    groupingsÚinsert)rbr¾rûrqÚlevrørcrcrdÚ_insert_inaxis_grouperCs
 
 ý zGroupBy._insert_inaxis_grouperz"Mapping[base.OutputKey, ArrayLike]cCs t|ƒ‚dSr`rÜ©rbr¾rcrcrdÚ_indexed_output_to_ndframeVsz"GroupBy._indexed_output_to_ndframecCs2|jdkr.|j}|j |jj¡r.|jj ¡|_|S)Nrº)r{r#rêrèr‚rârrcrcrdÚ_maybe_transpose_result[s
 
zGroupBy._maybe_transpose_resultznpt.NDArray[np.float64] | None)r¾ÚqscCsb|js*| |¡}| ¡}tt|jjƒƒ}n|jj}|dk    rDt||ƒ}||_    | 
|¡}|j ||dS)zÛ
        Wraps the output of GroupBy aggregations into the expected result.
 
        Parameters
        ----------
        result : Series, DataFrame
 
        Returns
        -------
        Series or DataFrame
        N©r) rzrZ _consolidaterMrär~rrãÚ_insert_quantile_levelrêrÚ_reindex_output)rbr¾rrêÚresrcrcrdÚ_wrap_aggregated_outputfs
 
 
zGroupBy._wrap_aggregated_outputr½)rîrÒrÑcCs t|ƒ‚dSr`rÜ)rbÚdatarîrÒrÑrcrcrdÚ_wrap_applied_outputszGroupBy._wrap_applied_output)r
c Cs¦|jj\}}}t||ƒ}tj||dd}|j||jd ¡}t|jj    ƒdkrTt
dƒ‚|j }t |t ƒr||jj    dj}    | |    ¡}| |¡ ¡}
t ||¡\} } | | |
|fS)NF)Z
allow_fillr¸rºzAMore than 1 grouping labels are not supported with engine='numba'r)r~rærSr8Útake_ndrër{Úto_numpyr‹rýÚNotImplementedErrorrêr–rNrqZget_level_valuesrZgenerate_slices) rbr
ÚidsrórÚ sorted_indexZ
sorted_idsÚ sorted_dataZ
index_dataZ    group_keyZsorted_index_dataÚstartsÚendsrcrcrdÚ _numba_prepœs&
ÿ
 
üzGroupBy._numba_preprzdict[str, bool] | None)r´Ú engine_kwargscGsº|jstdƒ‚|jdkr tdƒ‚|j}|jdkr4|n| ¡}| |¡\}}}}    tj|ft    |ƒŽ}
|
|    ||df|žŽ} |j
j } |jdkršd|j i} |   ¡} n
d|ji} |j| fd| i| —ŽS)    zp
        Perform groupby with a standard numerical aggregation function (e.g. mean)
        with Numba.
        z<as_index=False is not supported. Use .reset_index() instead.rºzaxis=1 is not supported.érrqrûrê)rzrr{r¯rírúrr:Zgenerate_shared_aggregatorrTr~rãrqÚravelrûÚ _constructor)rbr´rZaggregator_argsr
ÚdfrrrrZ
aggregatorr¾rêÚ result_kwargsrcrcrdÚ_numba_agg_general¶s*
ÿ
ÿÿ
 
 
 
zGroupBy._numba_agg_general)rcOsÀ|j}|jdkr|n| ¡}| |¡\}}}    }
t |¡tj|ft||ƒŽ} | |
|    ||t|j    ƒf|žŽ} | j
t   |    ¡dd} |j } |jdkr d|ji}|  ¡} n
d|j    i}|j| fd| i|—ŽS)a(
        Perform groupby transform routine with the numba engine.
 
        This routine mimics the data splitting routine of the DataSplitter class
        to generate the indices of each group in the sorted data and then passes the
        data and indices into a Numba jitted function.
        rrr¸rºrqrûrê)r¯rírúrrGÚ validate_udfZgenerate_numba_transform_funcrTr‹rûrër˜Úargsortrêrqrr)rbr´rrirjr
rrrrrZnumba_transform_funcr¾rêrrcrcrdÚ_transform_with_numba×s2    
ÿÿûú
 
 
 
 
zGroupBy._transform_with_numbacOsÐ|j}|jdkr|n| ¡}| |¡\}}}    }
t |¡tj|ft||ƒŽ} | |
|    ||t|j    ƒf|žŽ} |j
j } |jdkrŽd|j i}|   ¡} n
d|j    i}|j| fd| i|—Ž}|jsÌ| |¡}tt|ƒƒ|_|S)a*
        Perform groupby aggregation routine with the numba engine.
 
        This routine mimics the data splitting routine of the DataSplitter class
        to generate the indices of each group in the sorted data and then passes the
        data and indices into a Numba jitted function.
        rrºrqrûrê)r¯rírúrrGrZgenerate_numba_agg_funcrTr‹rûr~rãrqrrrzrrPrê)rbr´rrirjr
rrrrrZnumba_agg_funcr¾rêrrrcrcrdÚ_aggregate_with_numbaûs8    
ÿÿûú
 
 
 
 
zGroupBy._aggregate_with_numbarYZ    dataframerZ)Úinputr³c
sút ˆ¡‰tˆtƒrft|ˆƒrTt|ˆƒ}t|ƒr:|ˆˆŽSˆsBˆrPtdˆ›ƒ‚|Stdˆ›dƒ‚n8ˆsnˆrštˆƒrt    ˆƒ‡‡‡fdd„ƒ}qžtdƒ‚nˆ}t
ddƒHz|  ||j ¡}Wn.tk
rê|  ||j ¡YW5QR£SXW5QRX|S)Nz"Cannot pass arguments to property z$apply func should be callable, not 'rÊc
s4tjddˆ|fˆžˆŽW5QR£SQRXdS)NÚignore)Úall)r˜Zerrstate)Úg©rir´rjrcrdrk:szGroupBy.apply.<locals>.fz6func must be a callable if args or kwargs are suppliedzmode.chained_assignment)rµZis_builtin_funcr–roÚhasattrrrÚcallabler§Ú    TypeErrorrrr×r°r¯)rbr´rirjrrkr¾rcr$rdrm#s0
 
 
 
 
ÿ     *z GroupBy.applyr·z bool | None)rkr
rÒrÑÚis_aggr_cCs2|j |||j¡\}}|dkr"|}| ||||¡S)aÊ
        Apply function f in python space
 
        Parameters
        ----------
        f : callable
            Function to apply
        data : Series or DataFrame
            Data to apply f to
        not_indexed_same: bool, optional
            When specified, overrides the value of not_indexed_same. Apply behaves
            differently when the result index is equal to the input index, but
            this can be coincidental leading to value-dependent behavior.
        is_transform : bool, default False
            Indicator for whether the function is actually a transform
            and should not have group keys prepended.
        is_agg : bool, default False
            Indicator for whether the function is an aggregation. When the
            result is empty, we don't want to warn for this case.
            See _GroupBy._python_agg_general.
 
        Returns
        -------
        Series or DataFrame
            data after applying f
        N)r~rmr{r )rbrkr
rÒrÑr(rîZmutatedrcrcrdr×Ws#üzGroupBy._python_apply_generalràr‰©Ú numeric_onlyÚ    min_countÚaliasÚnpfunccCs"|j||||d}|j|jddS)N©ÚhowÚaltr*r+r^©Úmethod©Ú_cython_agg_generalÚ __finalize__r‚)rbr*r+r,r-r¾rcrcrdÚ _agg_general…s    üzGroupBy._agg_generalr)rîrír0r_cCs¨|dk    s t‚|jdkr$t|dd}n.t|jƒ}|jddks@t‚|jdd…df}|jj||dd}t    |t
ƒr„t |ƒj ||j d}n|j tkrœ|jtdd}t||d    S)
zn
        Fallback to pure-python aggregation if _cython_operation raises
        NotImplementedError.
        NrºF©rârT)Zpreserve_dtype©Údtype)rí)rÇrírRrDr#ÚshapeÚilocr~Z
agg_seriesr–r=rÈZ_from_sequencer9rŽÚastyperQ)rbrîrír0ZserrÚ
res_valuesrcrcrdÚ_agg_py_fallback–s 
 
 
 
zGroupBy._agg_py_fallbackr.c
 sdˆj|ˆd‰dddœ‡‡‡‡‡‡fdd„ }ˆ |¡}ˆ |¡}ˆ |¡}    ˆjdkr`|    jdd}    |    S)    N©r*rqr©rîr_csTz(ˆjjd|ˆfˆjdˆdœˆ—Ž}Wn&tk
rNˆj|ˆjˆd}YnX|S)NÚ    aggregaterº©r{r+)rír0)r~Ú_cython_operationrírr>)rîr¾©r0r
r/rjr+rbrcrdÚ
array_funcÐsýûú
z/GroupBy._cython_agg_general.<locals>.array_funcrºFr7)Ú_get_data_to_aggregateÚgrouped_reduceÚ_wrap_agged_managerr    r{Z infer_objects)
rbr/r0r*r+rjrEÚnew_mgrrÚoutrcrDrdr4Âs 
 
 
 
 zGroupBy._cython_agg_generalr)r/r*r{cKs t|ƒ‚dSr`rÜ)rbr/r*r{rjrcrcrdÚ_cython_transformêszGroupBy._cython_transform)Úenginerc
Osât|ƒr"|j|f|žd|i|—ŽSt |¡p.|}t|tƒsL|j|f|ž|ŽS|tjkrld|›d}t    |ƒ‚nr|tj
ks€|tj krt ||ƒ||ŽSt  |dd¡0t  |dd¡t ||ƒ||Ž}W5QRXW5QRX| |¡SdS)NrrÊz2' is not a valid function name for transform(name)rƒTrz)rUrrµZget_cython_funcr–roZ_transform_generalrFZtransform_kernel_allowlistr§Zcythonized_kernelsrÖrrÚ temp_setattrÚ_wrap_transform_fast_result)rbr´rLrrirjrªr¾rcrcrdÚ
_transformïs,ÿÿÿÿ
 
 
 
$zGroupBy._transformcCs˜|j}|jj\}}}|j|jj|jdd}|jjdkrZt     |j
|¡}|j ||j |j d}n:|jdkrhdn|j}|j||dd}|j| |j¡|d}|S)z7
        Fast transform path for aggregations.
        Frárº)rêrqr)r{Zconvert_indicesr¸)r¯r~rærìrãr{r‚rír8r rérrêrqZ_takerõrå)rbr¾r‚rrórJÚoutputr{rcrcrdrNs z#GroupBy._wrap_transform_fast_resultcCs¦t|ƒdkrtjgdd}nt t |¡¡}|rD|jj||jd}n^tjt|jj    ƒt
d}|  d¡d||  t ¡<t |t|jjdd…ƒdg¡j}|j |¡}|S)NrÚint64r8r¸FTrº)r‹r˜Úarrayr„Ú concatenater°rër{ÚemptyrêrˆÚfillr<r‰Útiler½r:r#Úwhere)rbr‘r|ÚfilteredrðrcrcrdÚ _apply_filter/s 
$ zGroupBy._apply_filterú
np.ndarray)Ú    ascendingr_c Cs2|jj\}}}t||ƒ}||t|ƒ}}|dkrBtjdtjdStjd|dd…|dd…kf}t tjt     |¡d|f¡}| 
¡}    |r¦|    t  |    ||¡8}    n&t  |    tj|dd…df|¡|    }    |jj röt  |dktj|    jtjdd¡}    n|    jtjdd}    tj|tjd}
tj|tjd|
|<|    |
S)    a.
        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from length of group - 1 to 0.
 
        Notes
        -----
        this is currently implementing sort=False
        (though the default is sort=True) for groupby in general
        rr8TNràrºFr7)r~rærSr‹r˜rTrQZr_ÚdiffZnonzeroÚcumsumÚrepeatrØrWÚnanr<Úfloat64ÚintpZarange) rbr[rrórZsorterÚcountÚrunÚreprJÚrevrcrcrdÚ_cumcount_array@s" 
"
&"zGroupBy._cumcount_arraycCs,t|jtƒr|jjSt|jtƒs$t‚|jjSr`)r–r‚rDZ_constructor_slicedrRrÇrrgrcrcrdÚ_obj_1d_constructorhs zGroupBy._obj_1d_constructorzLiteral[('any', 'all')])Úval_testÚskipnac    sLdddœ‡fdd„ }dddd    dd
œd d „}|jtjdt tj¡|||ˆd S)zO
        Shared func to call any / all Cython GroupBy implementations.
        rztuple[np.ndarray, type]©Úvalsr_cs^t|jƒr0ˆr0t|ƒ}| ¡r@| ¡}d||<nt|tƒr@|j}|jt    dd}| 
t j ¡t    fS)NTFr7) r3r9r6Úanyrâr–r;Ú_datar<rˆÚviewr˜Úint8)rkrð©rircrdÚ objs_to_boolws
 
z'GroupBy._bool_agg.<locals>.objs_to_boolFrZrÈrˆ)r¾Ú    inferenceÚnullabler_cSs.|rt|jtdd|dkƒS|j|ddSdS)NFr7rà)r<r<rˆ)r¾rrrsrcrcrdÚresult_to_bool„sz)GroupBy._bool_agg.<locals>.result_to_bool)r*Ú cython_dtypeÚpre_processingÚpost_processingrhri)F)Ú_get_cythonized_resultÚ
libgroupbyZ group_any_allr˜r9ro)rbrhrirqrtrcrprdÚ    _bool_aggqsý
 
ùzGroupBy._bool_aggr^rpcCs | d|¡S)a®
        Return True if any value in the group is truthful, else False.
 
        Parameters
        ----------
        skipna : bool, default True
            Flag to ignore nan values during truth testing.
 
        Returns
        -------
        Series or DataFrame
            DataFrame or Series of boolean values, where a value is True if any element
            is True within its respective group, False otherwise.
        rl©rz©rbrircrcrdrl˜sz GroupBy.anycCs | d|¡S)a²
        Return True if all values in the group are truthful, else False.
 
        Parameters
        ----------
        skipna : bool, default True
            Flag to ignore nan values during truth testing.
 
        Returns
        -------
        Series or DataFrame
            DataFrame or Series of boolean values, where a value is True if all elements
            are True within its respective group, False otherwise.
        r"r{r|rcrcrdr"¬sz GroupBy.allc    sˆ| ¡}|jj\‰}‰ˆdk‰|jdk‰dddœ‡‡‡‡fdd„ }| |¡}| |¡}t |dd¡| |¡}W5QRX|j    |d    d
S) z¯
        Compute count of group, excluding missing values.
 
        Returns
        -------
        Series or DataFrame
            Count of values within each group.
        ràrºr)Úbvaluesr_csp|jdkr"ˆt|ƒ dd¡@}nˆt|ƒ@}tj|ˆˆd}ˆrl|jdksRt‚|jddksdt‚|dS|S)Nrºrà)rïZmax_binrr)rír6ÚreshaperZcount_level_2drÇr:)r}ZmaskedZcounted©rZ    is_seriesrðrrcrdÚhfuncÒs
zGroupBy.count.<locals>.hfuncrƒTr©Ú
fill_value)
rFr~rærírGrHrµrMr    r)rbr
rór€rIÚnew_objr¾rcrrdrbÀs 
 
 
z GroupBy.count)Zsee_alsoÚcython)r*rLrcsLt|ƒr ddlm}| ||¡S|jd‡fdd„ˆd}|j|jddSd    S)
aW
        Compute mean of groups, excluding missing values.
 
        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.
 
            .. versionchanged:: 2.0.0
 
                numeric_only no longer accepts ``None`` and defaults to ``False``.
 
        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``
 
            .. versionadded:: 1.4.0
 
        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``
 
            .. versionadded:: 1.4.0
 
        Returns
        -------
        pandas.Series or pandas.DataFrame
        %(see_also)s
        Examples
        --------
        >>> df = pd.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()
             B         C
        A
        1  3.0  1.333333
        2  4.0  1.500000
 
        Groupby two columns and return the mean of the remaining column.
 
        >>> df.groupby(['A', 'B']).mean()
                 C
        A B
        1 2.0  2.0
          4.0  1.0
        2 3.0  1.0
          5.0  2.0
 
        Groupby one column and return the mean of only particular column in
        the group.
 
        >>> df.groupby('A')['B'].mean()
        A
        1    3.0
        2    4.0
        Name: B, dtype: float64
        r)Ú sliding_meanÚmeancst|ƒjˆdS©N©r*)rRr†rÍrˆrcrdr”Ar•zGroupBy.mean.<locals>.<lambda>©r0r*r^r1N)rUÚpandas.core._numba.kernelsr…rr4r5r‚)rbr*rLrr…r¾rcrˆrdr†ísM  
ýz GroupBy.meanrˆcs(|jd‡fdd„ˆd}|j|jddS)aø
        Compute median of groups, excluding missing values.
 
        For multiple groupings, the result index will be a MultiIndex
 
        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.
 
            .. versionchanged:: 2.0.0
 
                numeric_only no longer accepts ``None`` and defaults to False.
 
        Returns
        -------
        Series or DataFrame
            Median of values within each group.
        Úmediancst|ƒjˆdSr‡)rRr‹rÍrˆrcrdr”]r•z GroupBy.median.<locals>.<lambda>r‰r^r1r3)rbr*r¾rcrˆrdr‹Fs 
ýzGroupBy.medianrºz
str | None)ÚddofrLrr*c    
Csnt|ƒr(ddlm}t | |||¡¡Sdd„}dddd    œd
d „}|jtjt     tj
¡|d |||d d}|SdS)a¦
        Compute standard deviation of groups, excluding missing values.
 
        For multiple groupings, the result index will be a MultiIndex.
 
        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.
 
        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``
 
            .. versionadded:: 1.4.0
 
        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``
 
            .. versionadded:: 1.4.0
 
        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.
 
            .. versionadded:: 1.5.0
 
            .. versionchanged:: 2.0.0
 
                numeric_only now defaults to ``False``.
 
        Returns
        -------
        Series or DataFrame
            Standard deviation of values within each group.
        r©Ú sliding_varcSst|tƒr|jdfS|dfSr`)r–r;rm©rîrcrcrdÚ_preprocessing›s
 
z#GroupBy.std.<locals>._preprocessingFNrˆr)rsr_cSs@|r6|jdkr|dd…df}tt |¡| tj¡ƒSt |¡S)Nrr)rír@r˜ÚsqrtrnÚbool_)rkrrrsÚ result_maskrcrcrdÚ_postprocessing s
 
z$GroupBy.std.<locals>._postprocessingTÚstd)rur*Ú needs_countsrvrwrŒr/)FN) rUrŠrŽr˜r‘rrxryZ    group_varr9r`)    rbrŒrLrr*rŽrr”r¾rcrcrdr•bs$3 ÿ    
ø
z GroupBy.stdcs@t|ƒr"ddlm}| ||ˆ¡S|jd‡fdd„|ˆdSdS)a’
        Compute variance of groups, excluding missing values.
 
        For multiple groupings, the result index will be a MultiIndex.
 
        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.
 
        engine : str, default None
            * ``'cython'`` : Runs the operation through C-extensions from cython.
            * ``'numba'`` : Runs the operation through JIT compiled code from numba.
            * ``None`` : Defaults to ``'cython'`` or globally setting
              ``compute.use_numba``
 
            .. versionadded:: 1.4.0
 
        engine_kwargs : dict, default None
            * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
            * For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
              and ``parallel`` dictionary keys. The values must either be ``True`` or
              ``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
              ``{{'nopython': True, 'nogil': False, 'parallel': False}}``
 
            .. versionadded:: 1.4.0
 
        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.
 
            .. versionadded:: 1.5.0
 
            .. versionchanged:: 2.0.0
 
                numeric_only now defaults to ``False``.
 
        Returns
        -------
        Series or DataFrame
            Variance of values within each group.
        rrÚvarcst|ƒjˆdS)N©rŒ)rRr—rÍr˜rcrdr”ïr•zGroupBy.var.<locals>.<lambda>)r0r*rŒN)rUrŠrŽrr4)rbrŒrLrr*rŽrcr˜rdr—µs3 
üz GroupBy.varzSequence[Hashable] | None)ÚsubsetÚ    normalizer„r[r|r_c    s’|jdkrtdƒ‚|rdnd}|j}|j‰dd„|jjDƒ‰tˆtƒr`ˆj}|ˆkrXgnˆg}    nxt    ˆj
ƒ}
|dk    r¸t    |ƒ‰ˆt    ˆƒ@} | ršt d| ›d    ƒ‚ˆ|
} | r¼t d| ›d
ƒ‚n|
‰‡‡‡fd d „t ˆj
ƒDƒ}    t |jjƒ} |    D]0}t|||j|jd |d\}}}| t |jƒ7} qè|j| |j|j|jd}tt| ¡ƒ}||_tdd„| Dƒƒr–dd „| Dƒ}tj|dd „| Dƒd ¡\}}|j|dd}|rêt tt|jjƒ|jjƒƒ}|j|j |¡|j|jd d¡}||}|  d¡}|rtt|jjƒƒ}|j!|dj"|d d}|j#r$|}n^|j}t$ %|j&¡}||krPt d|›dƒ‚||_| 'tt|ƒƒ¡|_| (¡}||g|_
|}|j)|jddS) zø
        Shared implementation of value_counts for SeriesGroupBy and DataFrameGroupBy.
 
        SeriesGroupBy additionally supports a bins argument. See the docstring of
        DataFrameGroupBy.value_counts for a description of arguments.
        rºz1DataFrameGroupBy.value_counts only handles axis=0Z
proportionrbcSsh|]}|jr|j’qSrc©rørq©rœÚgroupingrcrcrdÚ    <setcomp> sz(GroupBy._value_counts.<locals>.<setcomp>NzKeys z0 in subset cannot be in the groupby column keys.z) in subset do not exist in the DataFrame.cs2g|]*\}}|ˆkr|ˆkrˆjdd…|f‘qSr`)r;)rœÚidxÚ_name©Z in_axis_namesr‚Z    subsettedrcrdr%sþz)GroupBy._value_counts.<locals>.<listcomp>F)r“r{r„rƒr|)r„rƒr|css&|]}t|jttfƒo|j VqdSr`)r–Úgrouping_vectorr=rLZ    _observedrœrcrcrdrŸDsþz(GroupBy._value_counts.<locals>.<genexpr>cSsg|]
}|j‘qSrc)rã©rœÚpingrcrcrdrIscSsg|]
}|j‘qSrcrpr£rcrcrdrKs©r©rr)r„r|Úsumg©r[)rZsort_remainingzColumn label 'z' is duplicate of result columnZ value_countsr1)*r{rr‚r¯r~rýr–rRrqÚsetrûr§Ú    enumerater½rIr„r^rƒr|rÚsizerlrNÚ from_productZ    sortlevelrìrär‹rêZnlevelsZ    droplevelZ    transformZfillnaÚ sort_valuesr÷rzrµZfill_missing_namesr©Z    set_namesÚ reset_indexr5)rbr™ršr„r[r|rqrr r€Z unique_colsZclashingZ doesnt_existrýr“r~róÚgbZ result_seriesÚ levels_listZ multi_indexrßZindexed_group_sizeZ index_levelr¾rêrûZ result_framercr¡rdÚ _value_countsôs²
ÿ ÿ
 
 
ÿ
ÿý ú üý
 ÿÿ
ýü
 ÿ 
 zGroupBy._value_counts©rŒr*cCsÎ|r>|jjdkr>t|jjƒs>tt|ƒj›d|›d|jj›ƒ‚|j||d}|jdkrj|t     | 
¡¡}n`|j   |j ¡ ¡}| 
¡}|j  |¡}|j  |¡}|jdd…|ft     |jdd…|f¡<|S)as
        Compute standard error of the mean of groups, excluding missing values.
 
        For multiple groupings, the result index will be a MultiIndex.
 
        Parameters
        ----------
        ddof : int, default 1
            Degrees of freedom.
 
        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.
 
            .. versionadded:: 1.5.0
 
            .. versionchanged:: 2.0.0
 
                numeric_only now defaults to ``False``.
 
        Returns
        -------
        Series or DataFrame
            Standard error of the mean of values within each group.
        rºz.sem called with numeric_only=z  and dtype r±N)r‚rír2r9r'rÈrlr•r˜r‘rbrûÚ
differencer}ÚuniqueZget_indexer_forr;)rbrŒr*r¾ÚcolsÚcountsröZ count_ilocsrcrcrdÚsemwsÿ
  .z GroupBy.semc    Cst|j ¡}t|jtƒr*|j||jjd}n
| |¡}t |dd¡|j    |dd}W5QRX|j
sp|  d¡  ¡}|S)zÝ
        Compute group sizes.
 
        Returns
        -------
        DataFrame or Series
            Number of rows in each group as a Series if as_index is True
            or a DataFrame if as_index is False.
        rprzTrrrª) r~rªr–r‚rRrgrqrµrMrrzÚrenamer­rrcrcrdrª£s
 
z GroupBy.sizer¦)ÚfnameÚnoZmc)r*r+rLrc    Cs`t|ƒr ddlm}| ||¡St |dd¡|j||dtjd}W5QRX|j    |ddSdS)Nr)Ú sliding_sumrƒTr¦r)r)
rUrŠrºrrµrMr6r˜r¦r)rbr*r+rLrrºr¾rcrcrdr¦Âs     þüz GroupBy.sumÚprod)r*r+cCs|j||dtjdS)Nr»r))r6r˜r»)rbr*r+rcrcrdr»às ÿz GroupBy.prodÚmincCs:t|ƒr"ddlm}| ||d¡S|j||dtjdSdS)Nr©Úsliding_min_maxFr¼r))rUrŠr¾rr6r˜r¼©rbr*r+rLrr¾rcrcrdr¼çs     üz GroupBy.minÚmaxcCs:t|ƒr"ddlm}| ||d¡S|j||dtjdSdS)Nrr½TrÀr))rUrŠr¾rr6r˜rÀr¿rcrcrdrÀüs     üz GroupBy.maxcCs$d    dddœdd„}|j||d|dS)
aÏ
        Compute the first non-null entry of each column.
 
        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns.
        min_count : int, default -1
            The required number of valid values to perform the operation. If fewer
            than ``min_count`` non-NA values are present the result will be NA.
 
        Returns
        -------
        Series or DataFrame
            First non-null of values within each group.
 
        See Also
        --------
        DataFrame.groupby : Apply a function groupby to each row or column of a
            DataFrame.
        pandas.core.groupby.DataFrameGroupBy.last : Compute the last non-null entry
            of each column.
        pandas.core.groupby.DataFrameGroupBy.nth : Take the nth row from each group.
 
        Examples
        --------
        >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[None, 5, 6], C=[1, 2, 3],
        ...                        D=['3/11/2000', '3/12/2000', '3/13/2000']))
        >>> df['D'] = pd.to_datetime(df['D'])
        >>> df.groupby("A").first()
             B  C          D
        A
        1  5.0  1 2000-03-11
        3  6.0  3 2000-03-13
        >>> df.groupby("A").first(min_count=2)
            B    C          D
        A
        1 NaN  1.0 2000-03-11
        3 NaN  NaN        NaT
        >>> df.groupby("A").first(numeric_only=True)
             B  C
        A
        1  5.0  1
        3  6.0  3
        rrr©r‚r{cSsHddœdd„}t|tƒr&|j||dSt|tƒr8||ƒStt|ƒƒ‚dS)NrRrÍcSs&|jt|jƒ}t|ƒstjS|dS)z-Helper function for first item that isn't NA.r©rRr7r‹r˜r_©rÎZarrrcrcrdÚfirstB    sz2GroupBy.first.<locals>.first_compat.<locals>.firstr¸©r–rDrmrRr'rÈ)r‚r{rÄrcrcrdÚ first_compatA    s 
 
z#GroupBy.first.<locals>.first_compatrÄr))r©r6)rbr*r+rÆrcrcrdrÄ    s0üz GroupBy.firstcCs$d    dddœdd„}|j||d|dS)
az
        Compute the last non-null entry of each column.
 
        Parameters
        ----------
        numeric_only : bool, default False
            Include only float, int, boolean columns. If None, will attempt to use
            everything, then use only numeric data.
        min_count : int, default -1
            The required number of valid values to perform the operation. If fewer
            than ``min_count`` non-NA values are present the result will be NA.
 
        Returns
        -------
        Series or DataFrame
            Last non-null of values within each group.
 
        See Also
        --------
        DataFrame.groupby : Apply a function groupby to each row or column of a
            DataFrame.
        pandas.core.groupby.DataFrameGroupBy.first : Compute the first non-null entry
            of each column.
        pandas.core.groupby.DataFrameGroupBy.nth : Take the nth row from each group.
 
        Examples
        --------
        >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[5, None, 6], C=[1, 2, 3]))
        >>> df.groupby("A").last()
             B  C
        A
        1  5.0  2
        3  6.0  3
        rrrrÁcSsHddœdd„}t|tƒr&|j||dSt|tƒr8||ƒStt|ƒƒ‚dS)NrRrÍcSs&|jt|jƒ}t|ƒstjS|dS)z,Helper function for last item that isn't NA.ràrÂrÃrcrcrdÚlast}    sz/GroupBy.last.<locals>.last_compat.<locals>.lastr¸rÅ)r‚r{rÈrcrcrdÚ last_compat|    s 
 
z!GroupBy.last.<locals>.last_compatrÈr))rrÇ)rbr*r+rÉrcrcrdrÈW    s%üz GroupBy.lastcCs |jjdkrl|j}t|jƒ}|s(tdƒ‚|jjd|jdddd}dd    d
d g}|jj    ||jj
|d }|  |¡S|  d d„|j ¡}|jsœ| |¡}tt|ƒƒ|_|S)a
        Compute open, high, low and close values of a group, excluding missing values.
 
        For multiple groupings, the result index will be a MultiIndex
 
        Returns
        -------
        DataFrame
            Open, high, low and close values within each group.
        rºzNo numeric types to aggregaterAÚohlcrràrBÚopenÚhighÚlowÚclose)rêrûcSs| ¡Sr`)rÊrÍrcrcrdr”±    r•zGroupBy.ohlc.<locals>.<lambda>)r‚rír°r2r9r'r~rCréZ_constructor_expanddimrãrZ_apply_to_column_groupbysr¯rzrrPr‹rê)rbr‚Z
is_numericr=Z    agg_namesr¾rcrcrdrÊ’    s6 
ÿ ÿ
ÿ
z GroupBy.ohlcc    s¾|j}t|ƒdkrN|jˆˆˆd}|jdkr2|}n| ¡}| ¡jjdd…St     |dd¡"|j
‡‡‡fdd„|dd}W5QRX|j dkr”|jS| ¡}|j sº|  |¡}tt|ƒƒ|_|S)    Nr©Ú percentilesÚincludeÚexcluderºrzTcs|jˆˆˆdS)NrÏ)ÚdescriberÍ©rÒrÑrÐrcrdr”Í    sÿz"GroupBy.describe.<locals>.<lambda>)rÒ)r¯r‹rÓríZunstackrúr#r;rµrMr×r{rzrrPrê)rbrÐrÑrÒr‚Z    describedr¾rcrÔrdrÓ¸    s0 ÿ
û
 
zGroupBy.describecOsddlm}|||f|ž|ŽS)a<
        Provide resampling when using a TimeGrouper.
 
        Given a grouper, the function resamples it according to a string
        "string" -> "frequency".
 
        See the :ref:`frequency aliases <timeseries.offset_aliases>`
        documentation for more details.
 
        Parameters
        ----------
        rule : str or DateOffset
            The offset string or object representing target grouper conversion.
        *args, **kwargs
            Possible arguments are `how`, `fill_method`, `limit`, `kind` and
            `on`, and other arguments of `TimeGrouper`.
 
        Returns
        -------
        Grouper
            Return a new grouper with our resampler appended.
 
        See Also
        --------
        Grouper : Specify a frequency to resample with when
            grouping by a key.
        DatetimeIndex.resample : Frequency conversion and resampling of
            time series.
 
        Examples
        --------
        >>> idx = pd.date_range('1/1/2000', periods=4, freq='T')
        >>> df = pd.DataFrame(data=4 * [range(2)],
        ...                   index=idx,
        ...                   columns=['a', 'b'])
        >>> df.iloc[2, 0] = 5
        >>> df
                            a  b
        2000-01-01 00:00:00  0  1
        2000-01-01 00:01:00  0  1
        2000-01-01 00:02:00  5  1
        2000-01-01 00:03:00  0  1
 
        Downsample the DataFrame into 3 minute bins and sum the values of
        the timestamps falling into a bin.
 
        >>> df.groupby('a').resample('3T').sum()
                                 a  b
        a
        0   2000-01-01 00:00:00  0  2
            2000-01-01 00:03:00  0  1
        5   2000-01-01 00:00:00  5  1
 
        Upsample the series into 30 second bins.
 
        >>> df.groupby('a').resample('30S').sum()
                            a  b
        a
        0   2000-01-01 00:00:00  0  1
            2000-01-01 00:00:30  0  0
            2000-01-01 00:01:00  0  1
            2000-01-01 00:01:30  0  0
            2000-01-01 00:02:00  0  0
            2000-01-01 00:02:30  0  0
            2000-01-01 00:03:00  0  1
        5   2000-01-01 00:02:00  5  1
 
        Resample by month. Values are assigned to the month of the period.
 
        >>> df.groupby('a').resample('M').sum()
                    a  b
        a
        0   2000-01-31  0  3
        5   2000-01-31  5  1
 
        Downsample the series into 3 minute bins as above, but close the right
        side of the bin interval.
 
        >>> df.groupby('a').resample('3T', closed='right').sum()
                                 a  b
        a
        0   1999-12-31 23:57:00  0  1
            2000-01-01 00:00:00  0  2
        5   2000-01-01 00:00:00  5  1
 
        Downsample the series into 3 minute bins and close the right side of
        the bin interval, but label each bin using the right edge instead of
        the left.
 
        >>> df.groupby('a').resample('3T', closed='right', label='right').sum()
                                 a  b
        a
        0   2000-01-01 00:00:00  0  1
            2000-01-01 00:03:00  0  2
        5   2000-01-01 00:03:00  5  1
        r)Úget_resampler_for_grouping)Zpandas.core.resamplerÕ)rbZrulerirjrÕrcrcrdÚresampleÞ    sb zGroupBy.resamplerXcOs,ddlm}||jf|ž|j|jdœ|—ŽS)a™
        Return a rolling grouper, providing rolling functionality per group.
 
        Parameters
        ----------
        window : int, timedelta, str, offset, or BaseIndexer subclass
            Size of the moving window.
 
            If an integer, the fixed number of observations used for
            each window.
 
            If a timedelta, str, or offset, the time period of each window. Each
            window will be a variable sized based on the observations included in
            the time-period. This is only valid for datetimelike indexes.
            To learn more about the offsets & frequency strings, please see `this link
            <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.
 
            If a BaseIndexer subclass, the window boundaries
            based on the defined ``get_window_bounds`` method. Additional rolling
            keyword arguments, namely ``min_periods``, ``center``, ``closed`` and
            ``step`` will be passed to ``get_window_bounds``.
 
        min_periods : int, default None
            Minimum number of observations in window required to have a value;
            otherwise, result is ``np.nan``.
 
            For a window that is specified by an offset,
            ``min_periods`` will default to 1.
 
            For a window that is specified by an integer, ``min_periods`` will default
            to the size of the window.
 
        center : bool, default False
            If False, set the window labels as the right edge of the window index.
 
            If True, set the window labels as the center of the window index.
 
        win_type : str, default None
            If ``None``, all points are evenly weighted.
 
            If a string, it must be a valid `scipy.signal window function
            <https://docs.scipy.org/doc/scipy/reference/signal.windows.html#module-scipy.signal.windows>`__.
 
            Certain Scipy window types require additional parameters to be passed
            in the aggregation function. The additional parameters must match
            the keywords specified in the Scipy window type method signature.
 
        on : str, optional
            For a DataFrame, a column label or Index level on which
            to calculate the rolling window, rather than the DataFrame's index.
 
            Provided integer column is ignored and excluded from result since
            an integer index is not used to calculate the rolling window.
 
        axis : int or str, default 0
            If ``0`` or ``'index'``, roll across the rows.
 
            If ``1`` or ``'columns'``, roll across the columns.
 
            For `Series` this parameter is unused and defaults to 0.
 
        closed : str, default None
            If ``'right'``, the first point in the window is excluded from calculations.
 
            If ``'left'``, the last point in the window is excluded from calculations.
 
            If ``'both'``, the no points in the window are excluded from calculations.
 
            If ``'neither'``, the first and last points in the window are excluded
            from calculations.
 
            Default ``None`` (``'right'``).
 
        method : str {'single', 'table'}, default 'single'
            Execute the rolling operation per single column or row (``'single'``)
            or over the entire object (``'table'``).
 
            This argument is only implemented when specifying ``engine='numba'``
            in the method call.
 
        Returns
        -------
        RollingGroupby
            Return a new grouper with our rolling appended.
 
        See Also
        --------
        Series.rolling : Calling object with Series data.
        DataFrame.rolling : Calling object with DataFrames.
        Series.groupby : Apply a function groupby to a Series.
        DataFrame.groupby : Apply a function groupby.
 
        Examples
        --------
        >>> df = pd.DataFrame({'A': [1, 1, 2, 2],
        ...                    'B': [1, 2, 3, 4],
        ...                    'C': [0.362, 0.227, 1.267, -0.562]})
        >>> df
              A  B      C
        0     1  1  0.362
        1     1  2  0.227
        2     2  3  1.267
        3     2  4 -0.562
 
        >>> df.groupby('A').rolling(2).sum()
            B      C
        A
        1 0  NaN    NaN
          1  3.0  0.589
        2 2  NaN    NaN
          3  7.0  0.705
 
        >>> df.groupby('A').rolling(2, min_periods=1).sum()
            B      C
        A
        1 0  1.0  0.362
          1  3.0  0.589
        2 2  3.0  1.267
          3  7.0  0.705
 
        >>> df.groupby('A').rolling(2, on='B').sum()
            B      C
        A
        1 0  1    NaN
          1  2  0.589
        2 2  3    NaN
          3  4  0.705
        r)rX)Ú_grouperZ    _as_index)Úpandas.core.windowrXr°r~rz)rbrirjrXrcrcrdÚrollingD
s ÿþüûzGroupBy.rollingrVcOs(ddlm}||jf|žd|ji|—ŽS)zc
        Return an expanding grouper, providing expanding
        functionality per group.
        r)rVr×)rØrVr°r~)rbrirjrVrcrcrdÚ    expandingÐ
s ÿþýüzGroupBy.expandingrWcOs(ddlm}||jf|žd|ji|—ŽS)zO
        Return an ewm grouper, providing ewm functionality per group.
        r)rWr×)rØrWr°r~)rbrirjrWrcrcrdÚewmá
s ÿþýüz GroupBy.ewmzLiteral[('ffill', 'bfill')])Ú    directionc
s¼|dkr d}ˆjj\}}}tj|ddjtjdd}|dkrJ|ddd…}ttj||||ˆj    d‰d    d    d
œ‡‡fd d „ }ˆ 
¡}|  |¡}ˆ  |¡}    ˆj d kr®|    j}    ˆjj|    _ˆjj|    _|    S)a 
        Shared function for `pad` and `backfill` to call Cython method.
 
        Parameters
        ----------
        direction : {'ffill', 'bfill'}
            Direction passed to underlying Cython function. `bfill` will cause
            values to be filled backwards. `ffill` and any other values will
            default to a forward fill
        limit : int, default None
            Maximum number of consecutive values to fill. If `None`, this
            method will convert to -1 prior to passing to Cython
 
        Returns
        -------
        `Series` or `DataFrame` with filled values
 
        See Also
        --------
        pad : Returns Series with minimum number of char in object.
        backfill : Backward fill the missing values in the dataset.
        NràZ    mergesort)ÚkindFr7Úbfill)rïÚ sorted_labelsrÜÚlimitr|rr@csàt|ƒ}|jdkr<tj|jtjd}ˆ||dt ||¡St|tj    ƒrr|j
}ˆj j r`t |j
ƒ}tj|j|d}nt|ƒj|j|j
d}t|ƒD]F\}}tj|jdtjd}ˆ|||dt ||¡||dd…f<q|SdS)Nrºr8)rJrð)r6rír˜rTr:rar8r r–Zndarrayr9r~rØr,rÈÚ_emptyr©)rîrðròr9rJÚiZ value_element©Zcol_funcrbrcrdÚblk_func s 
 
 
zGroupBy._fill.<locals>.blk_funcrº)r~rær˜rr<rarryZgroup_fillna_indexerr|rFrmrHr{r#r‚rûrê)
rbrÜràrrórßräÚmgrÚres_mgrrƒrcrãrdÚ_fillñ
s.ú    
 
 
 
 
z GroupBy._fillcCs|jd|dS)a:
        Forward fill the values.
 
        Parameters
        ----------
        limit : int, optional
            Limit of how many values to fill.
 
        Returns
        -------
        Series or DataFrame
            Object with missing values filled.
 
        See Also
        --------
        Series.ffill: Returns Series with minimum number of char in object.
        DataFrame.ffill: Object with missing values filled or None if inplace=True.
        Series.fillna: Fill NaN values of a Series.
        DataFrame.fillna: Fill NaN values of a DataFrame.
        Úffill©rà©rç©rbràrcrcrdrèG sz GroupBy.ffillcCs|jd|dS)a/
        Backward fill the values.
 
        Parameters
        ----------
        limit : int, optional
            Limit of how many values to fill.
 
        Returns
        -------
        Series or DataFrame
            Object with missing values filled.
 
        See Also
        --------
        Series.bfill :  Backward fill the missing values in the dataset.
        DataFrame.bfill:  Backward fill the missing values in the dataset.
        Series.fillna: Fill NaN values of a Series.
        DataFrame.fillna: Fill NaN values of a DataFrame.
        rÞrérêrërcrcrdrÞ` sz GroupBy.bfillrKcCst|ƒS)aÞ
        Take the nth row from each group if n is an int, otherwise a subset of rows.
 
        Can be either a call or an index. dropna is not available with index notation.
        Index notation accepts a comma separated list of integers and slices.
 
        If dropna, will take the nth non-null row, dropna is either
        'all' or 'any'; this is equivalent to calling dropna(how=dropna)
        before the groupby.
 
        Parameters
        ----------
        n : int, slice or list of ints and slices
            A single nth value for the row or a list of nth values or slices.
 
            .. versionchanged:: 1.4.0
                Added slice and lists containing slices.
                Added index notation.
 
        dropna : {'any', 'all', None}, default None
            Apply the specified dropna operation before counting which row is
            the nth row. Only supported if n is an int.
 
        Returns
        -------
        Series or DataFrame
            N-th value within each group.
        %(see_also)s
        Examples
        --------
 
        >>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
        ...                    'B': [np.nan, 2, 3, 4, 5]}, columns=['A', 'B'])
        >>> g = df.groupby('A')
        >>> g.nth(0)
           A   B
        0  1 NaN
        2  2 3.0
        >>> g.nth(1)
           A   B
        1  1 2.0
        4  2 5.0
        >>> g.nth(-1)
           A   B
        3  1 4.0
        4  2 5.0
        >>> g.nth([0, 1])
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
        4  2 5.0
        >>> g.nth(slice(None, -1))
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
 
        Index notation may also be used
 
        >>> g.nth[0, 1]
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
        4  2 5.0
        >>> g.nth[:-1]
           A   B
        0  1 NaN
        1  1 2.0
        2  2 3.0
 
        Specifying `dropna` allows ignoring ``NaN`` values
 
        >>> g.nth(0, dropna='any')
           A   B
        1  1 2.0
        2  2 3.0
 
        When the specified ``n`` is larger than any of the groups, an
        empty DataFrame is returned
 
        >>> g.nth(3, dropna='any')
        Empty DataFrame
        Columns: [A, B]
        Index: []
        )rKrgrcrcrdÚnthy s\z GroupBy.nthzPositionalIndexer | tuplezLiteral[('any', 'all', None)])ržr|r_c Cs|s6| |¡}|jj\}}}||dk@}| |¡}|St|ƒsFtdƒ‚|dkr^td|›dƒ‚tt|ƒ}|jj    ||j
d}|j dkrÖ|j dkrÖ|jj
}|jj | |j¡}    |jjrö|    dk}
t |
t|    ¡} t| dd}    n t||j |j
|j |jd    \}    }}|j|    |j|j|j
d
} |  |¡S) Nràz4dropna option only supported for an integer argument)rlr"z_For a DataFrame or Series groupby.nth, dropna must be either None, 'any' or 'all', (was passed z).)r/r{ZInt64r8)r“r{rr„)rzr„r{)Ú"_make_mask_from_positional_indexerr~ræÚ_mask_selected_objr0r§rr‰r‚r|r{r€rZ
codes_infoÚisinrêrØr˜rWrrMrIr„r^rzrì) rbržr|rðrrórJZdroppedr{r~ZnullsrîZgrbrcrcrdÚ_nth× sF
 
 
ÿ
û ÿz GroupBy._nthçà?Úlinearzfloat | AnyArrayLike)ÚqÚ interpolationr*c sþdddœdd„‰dddddd    œ‡fd
d „ ‰t|ƒ}|r<|g}tj|tjd }|jj\}}‰t|ƒ‰ttj    ||ˆd ‰t|ƒdkrŒ| 
¡dnd}t  |dk||¡‰dddœ‡‡‡‡‡‡fdd„ }    |j |dd}
|
  |    ¡} | | ¡} |rð| | ¡S|j| |dS)a
        Return group values at the given quantile, a la numpy.percentile.
 
        Parameters
        ----------
        q : float or array-like, default 0.5 (50% quantile)
            Value(s) between 0 and 1 providing the quantile(s) to compute.
        interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
            Method to use when the desired quantile falls between two points.
        numeric_only : bool, default False
            Include only `float`, `int` or `boolean` data.
 
            .. versionadded:: 1.5.0
 
            .. versionchanged:: 2.0.0
 
                numeric_only now defaults to ``False``.
 
        Returns
        -------
        Series or DataFrame
            Return type determined by caller of GroupBy object.
 
        See Also
        --------
        Series.quantile : Similar method for Series.
        DataFrame.quantile : Similar method for DataFrame.
        numpy.percentile : NumPy method to compute qth percentile.
 
        Examples
        --------
        >>> df = pd.DataFrame([
        ...     ['a', 1], ['a', 2], ['a', 3],
        ...     ['b', 1], ['b', 3], ['b', 5]
        ... ], columns=['key', 'val'])
        >>> df.groupby('key').quantile()
            val
        key
        a    2.0
        b    3.0
        rz"tuple[np.ndarray, DtypeObj | None]rjcSsøt|ƒrtdƒ‚d}t|tƒr@t|jƒr@|jttj    d}|j}n°t
|jƒrxt|t ƒrf|jttj    d}n|}t tj ¡}nxt |jƒržt|t ƒrž|jttj    d}nRt|jƒr¶|j}||fSt|t ƒræt|ƒræt tj¡}|jttj    d}n
t |¡}||fS)Nz7'quantile' cannot be performed against 'object' dtypes!)r9Zna_value)r3r'r–r;r2r9r Úfloatr˜r_r1r?rQr-r5r.r`Zasarray)rkrrrJrcrcrdÚ pre_processorH s.ÿ
 
 
 
z'GroupBy.quantile.<locals>.pre_processorrZzDtypeObj | Noneznp.ndarray | None)rkrrr“Ú    orig_valsr_cs |rœt|tƒrL|dk    st‚ˆdkr4t|ƒs4t||ƒSt|ƒ| |j¡|ƒSnPt|ƒr\ˆdksœt    |ƒr‚| d¡ 
|j j ¡}|  |¡St|tj ƒs’t‚| |¡S|S)N>ÚmidpointròÚi8)r–r;rÇr.r@rÈr<Z numpy_dtyper1r5rnZ_ndarrayr9Z_from_backing_datar˜)rkrrr“r÷)rôrcrdÚpost_processork s6
 
ÿ
ÿüÿþ
ÿÿ
z(GroupBy.quantile.<locals>.post_processorr8)rïrrôrrºràr@c sb|}t|tƒr*|j}tjˆˆftjd}n t|ƒ}d}t|jƒ}ˆ|ƒ\}}d}|j    dkrz|j
d}t  ˆ|t ˆƒf¡}nˆ}tj |ˆˆftjd}    ||f}
t |
¡jtjdd} |rÈ| d¡ tj¡}|j    dkrêˆ|    d||| |dn.t|ƒD]$} ˆ|    | || || | | d    qò|j    dkrD|     d
¡}    |dk    rT| d
¡}n|     |ˆˆ¡}    ˆ|    |||ƒS) Nr8rºrrFr7rù)rîrðÚ sort_indexerr“)rîrðrûÚK)r–r;Z_maskr˜Úzerosr’r6r5r9rír:Z broadcast_tor‹rTr`Zlexsortr<rarnrärr~) rîr÷rðr“Úis_datetimelikerkrrÚncolsZ shaped_labelsrJÚorderZsort_arrrâ)r´Úlabels_for_lexsortrÚnqsrúrörcrdrä° sJ
 
 
 
 
ÿ
û " 
 
 z"GroupBy.quantile.<locals>.blk_funcÚquantiler?r)r4r˜rRr`r~rær‹rryZgroup_quantilerÀrWrFrGrHr    ) rbrórôr*Z orig_scalarrrróZna_label_for_sortingrär
rærrc)r´rôrrrrúrördr s.1#/ÿ6
 
 
zGroupBy.quantiler§cCs”|j}| |j¡}|jjd}|jjrBt |dktj|¡}tj    }ntj
}t dd„|jj Dƒƒrnt |ddd}|j|||d}|s|jd|}|S)    a
        Number each group from 0 to the number of groups - 1.
 
        This is the enumerative complement of cumcount.  Note that the
        numbers given to the groups match the order in which the groups
        would be seen when iterating over the groupby object, not the
        order they are first observed.
 
        Groups with missing keys (where `pd.isna()` is True) will be labeled with `NaN`
        and will be skipped from the count.
 
        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from number of group - 1 to 0.
 
        Returns
        -------
        Series
            Unique numbers for each group.
 
        See Also
        --------
        .cumcount : Number the rows in each group.
 
        Examples
        --------
        >>> df = pd.DataFrame({"color": ["red", None, "red", "blue", "blue", "red"]})
        >>> df
           color
        0    red
        1   None
        2    red
        3   blue
        4   blue
        5    red
        >>> df.groupby("color").ngroup()
        0    1.0
        1    NaN
        2    1.0
        3    0.0
        4    0.0
        5    1.0
        dtype: float64
        >>> df.groupby("color", dropna=False).ngroup()
        0    1
        1    2
        2    1
        3    0
        4    0
        5    1
        dtype: int64
        >>> df.groupby("color", dropna=False).ngroup(ascending=False)
        0    1
        1    0
        2    1
        3    2
        4    2
        5    1
        dtype: int64
        rràcss|] }|jVqdSr`)Z_passed_categoricalr£rcrcrdrŸ; sz!GroupBy.ngroup.<locals>.<genexpr>Zdense)Ú ties_methodrºr8)r¯rår{r~rærØr˜rWr_r`rQrlrýrrgr)rbr[r‚rêZcomp_idsr9r¾rcrcrdÚngroupð s@  zGroupBy.ngroupcCs&|j |j¡}|j|d}| ||¡S)aƒ
        Number each item in each group from 0 to the length of that group - 1.
 
        Essentially this is equivalent to
 
        .. code-block:: python
 
            self.apply(lambda x: pd.Series(np.arange(len(x)), x.index))
 
        Parameters
        ----------
        ascending : bool, default True
            If False, number in reverse, from length of group - 1 to 0.
 
        Returns
        -------
        Series
            Sequence number of each element within each group.
 
        See Also
        --------
        .ngroup : Number the groups themselves.
 
        Examples
        --------
        >>> df = pd.DataFrame([['a'], ['a'], ['a'], ['b'], ['b'], ['a']],
        ...                   columns=['A'])
        >>> df
           A
        0  a
        1  a
        2  a
        3  b
        4  b
        5  a
        >>> df.groupby('A').cumcount()
        0    0
        1    1
        2    2
        3    0
        4    1
        5    3
        dtype: int64
        >>> df.groupby('A').cumcount(ascending=False)
        0    3
        1    2
        2    1
        3    1
        4    0
        5    0
        dtype: int64
        r§)r¯rår{rfrg)rbr[rêZ    cumcountsrcrcrdÚcumcountD s7 zGroupBy.cumcountÚaverageÚkeep)r2r[Ú    na_optionÚpctr{r_c    sr|dkrd}t|ƒ‚||||dœ‰ˆdkr\ˆ d¡ˆd<‡‡fdd„}|j||jd    d
}|S|jdd ˆd œˆ—ŽS)a_
 
        Provide the rank of values within each group.
 
        Parameters
        ----------
        method : {'average', 'min', 'max', 'first', 'dense'}, default 'average'
            * average: average rank of group.
            * min: lowest rank in group.
            * max: highest rank in group.
            * first: ranks assigned in order they appear in the array.
            * dense: like 'min', but rank always increases by 1 between groups.
        ascending : bool, default True
            False for ranks by high (1) to low (N).
        na_option : {'keep', 'top', 'bottom'}, default 'keep'
            * keep: leave NA values where they are.
            * top: smallest rank if ascending.
            * bottom: smallest rank if descending.
        pct : bool, default False
            Compute percentage rank of data within each group.
        axis : int, default 0
            The axis of the object over which to compute the rank.
 
        Returns
        -------
        DataFrame with ranking of values within each group
        %(see_also)s
        Examples
        --------
        >>> df = pd.DataFrame(
        ...     {
        ...         "group": ["a", "a", "a", "a", "a", "b", "b", "b", "b", "b"],
        ...         "value": [2, 4, 2, 3, 5, 1, 2, 4, 1, 5],
        ...     }
        ... )
        >>> df
          group  value
        0     a      2
        1     a      4
        2     a      2
        3     a      3
        4     a      5
        5     b      1
        6     b      2
        7     b      4
        8     b      1
        9     b      5
        >>> for method in ['average', 'min', 'max', 'dense', 'first']:
        ...     df[f'{method}_rank'] = df.groupby('group')['value'].rank(method)
        >>> df
          group  value  average_rank  min_rank  max_rank  dense_rank  first_rank
        0     a      2           1.5       1.0       2.0         1.0         1.0
        1     a      4           4.0       4.0       4.0         3.0         4.0
        2     a      2           1.5       1.0       2.0         1.0         2.0
        3     a      3           3.0       3.0       3.0         2.0         3.0
        4     a      5           5.0       5.0       5.0         4.0         5.0
        5     b      1           1.5       1.0       2.0         1.0         1.0
        6     b      2           3.0       3.0       3.0         2.0         3.0
        7     b      4           4.0       4.0       4.0         3.0         4.0
        8     b      1           1.5       1.0       2.0         1.0         2.0
        9     b      5           5.0       5.0       5.0         4.0         5.0
        >ÚtoprÚbottomz3na_option must be one of 'keep', 'top', or 'bottom')rr[r    r
rrr2cs|jfˆddœˆ—ŽS)NF)r{r*)ÚrankrÍ©r{rjrcrdr”Ô r•zGroupBy.rank.<locals>.<lambda>T©rÑr F)r*r{)r )r§Úpopr×r°rK)    rbr2r[r    r
r{rªrkr¾rcrrdr  s2Hüÿÿýüz GroupBy.rank)r{r_csHt d|ˆddg¡ˆdkr<‡‡fdd„}|j||jddS|jd    ˆŽS)
zq
        Cumulative product for each group.
 
        Returns
        -------
        Series or DataFrame
        Úcumprodr*rircs|jfdˆiˆ—ŽS©Nr{)rrÍrrcrdr”î r•z!GroupBy.cumprod.<locals>.<lambda>Tr)r©ÚnvZvalidate_groupby_funcr×r°rK©rbr{rirjrkrcrrdrá s
zGroupBy.cumprodcsHt d|ˆddg¡ˆdkr<‡‡fdd„}|j||jddS|jd    ˆŽS)
zm
        Cumulative sum for each group.
 
        Returns
        -------
        Series or DataFrame
        r]r*rircs|jfdˆiˆ—ŽSr)r]rÍrrcrdr”r•z GroupBy.cumsum.<locals>.<lambda>Tr)r]rrrcrrdr]ó s
zGroupBy.cumsum)r{r*r_c sR| dd¡}ˆdkrB‡fdd„}|j}|r2| ¡}|j||ddS|jd||dS)    zm
        Cumulative min for each group.
 
        Returns
        -------
        Series or DataFrame
        riTrcstj |ˆ¡Sr`)r˜ZminimumÚ
accumulaterÍr¸rcrdr”r•z GroupBy.cummin.<locals>.<lambda>rÚcummin©r*ri©r¤r°Z_get_numeric_datar×rK©rbr{r*rjrirkr‚rcr¸rdrs  ÿzGroupBy.cumminc sR| dd¡}ˆdkrB‡fdd„}|j}|r2| ¡}|j||ddS|jd||dS)    zm
        Cumulative max for each group.
 
        Returns
        -------
        Series or DataFrame
        riTrcstj |ˆ¡Sr`)r˜ÚmaximumrrÍr¸rcrdr”-r•z GroupBy.cummax.<locals>.<lambda>rÚcummaxrrrrcr¸rdrs  ÿzGroupBy.cummaxÚany_allznp.dtype)Ú    base_funcrur*r–r/c     s”ˆrtˆƒstdƒ‚ˆr(tˆƒs(tdƒ‚|j}    |    j\}
} ‰tˆ|
d‰dddœ‡‡‡‡‡‡‡‡fdd„ } |j|ˆd} |  | ¡}| |¡}| |¡S)    aÀ
        Get result for Cythonized functions.
 
        Parameters
        ----------
        base_func : callable, Cythonized function to be called
        cython_dtype : np.dtype
            Type of the array that will be modified by the Cython call.
        numeric_only : bool, default False
            Whether only numeric datatypes should be computed
        needs_counts : bool, default False
            Whether the counts should be a part of the Cython call
        pre_processing : function, default None
            Function to be applied to `values` prior to passing to Cython.
            Function should return a tuple where the first element is the
            values to be passed to Cython and the second element is an optional
            type which the values should be converted to after being returned
            by the Cython operation. This function is also responsible for
            raising a TypeError if the values have an invalid type. Raises
            if `needs_values` is False.
        post_processing : function, default None
            Function to be applied to result of Cython function. Should accept
            an array of values as the first argument and type inferences as its
            second argument, i.e. the signature should be
            (ndarray, Type). If `needs_nullable=True`, a third argument should be
            `nullable`, to allow for processing specific to nullable values.
        how : str, default any_all
            Determines if any/all cython interface or std interface is used.
        **kwargs : dict
            Extra arguments to be passed back to Cython funcs
 
        Returns
        -------
        `Series` or `DataFrame`  with filled values
        z%'post_processing' must be a callable!z$'pre_processing' must be a callable!)rïrr@c     sl|j}|jdkrdn|jd}tjˆ|ˆd}| ˆ|f¡}tˆ|d}d}ˆrntjˆtjd}t||d}|jj    dk}|}|r”ˆdkr”| 
d¡}ˆr¤ˆ|ƒ\}}|j ˆdd    }|jdkrÆ| d
¡}t||d }ˆdksæt |t ƒrt|ƒ 
tj¡}|jdkr| d d¡}t||d }ˆdkr<t |t ƒ}    t||    d}n*t |t ƒrftj|jtjd}
t||
d}ˆdkr„|fˆd|i—Žn
|fˆŽ|jdkrÄ|jddks´t|jƒ‚|dd…df}ˆri} t |t ƒ| d<ˆdkrø| drø|
| d<ˆ||f| Ž}ˆdkrf|rftd|ƒ}|j} t ¡ t d¡|j tjdd    }W5QRX| 
d| ›d¡}|jS)Nrºr8)rJ)rµ)ÚmÚMr•rùFr7)ràrºrrà)rð)rs)r“rþrrsr“zDatetimeArray | TimedeltaArrayr!zm8[ú])r#rír:r˜rýr~rrQr9rÝrnr<r–r;r6Zuint8r’rÇrÚunitÚwarningsÚcatch_warningsÚfilterwarnings) rîrÿr¾r´Z
inferencesrµrþrkrðZ is_nullabler“Z    pp_kwargsr"©rrur/rjr–rrwrvrcrdräqsd    
 
 
 
 
 
 
 
 
 
z0GroupBy._get_cythonized_result.<locals>.blk_funcr?)    r&r§r~rærrFrGrHr    )rbrrur*r–rvrwr/rjr~rrórärårærJrcr&rdrx7s/    "H
 
zGroupBy._get_cythonized_result©Úperiodsr{c s’ˆdk    sˆdkr4‡‡‡‡fdd„}|j||jddS|jj\}}}tjt|ƒtjd}    t     |    ||ˆ¡|j
}
|
j |j |
j |j |    fiˆdd} | S)    a¥
        Shift each group by periods observations.
 
        If freq is passed, the index will be increased using the periods and the freq.
 
        Parameters
        ----------
        periods : int, default 1
            Number of periods to shift.
        freq : str, optional
            Frequency string.
        axis : axis to shift, default 0
            Shift direction.
        fill_value : optional
            The scalar value to use for newly introduced missing values.
 
        Returns
        -------
        Series or DataFrame
            Object shifted within each group.
 
        See Also
        --------
        Index.shift : Shift values of Index.
        Nrcs| ˆˆˆˆ¡Sr`)ÚshiftrÍ©r{r‚Úfreqr(rcrdr”Ýr•zGroupBy.shift.<locals>.<lambda>Trr8)r‚Z
allow_dups)r×r°r~rær˜rýr‹rQryZgroup_shift_indexerr¯Z_reindex_with_indexersr{rç) rbr(r+r{r‚rkrrórZ res_indexerr‚rrcr*rdr)Àsýz GroupBy.shift)r(r{r_cs”ˆdkr| ‡‡fdd„¡S|j}|jˆˆd}ddg‰|jdkrX|jˆkrŒ| d¡}n4‡fd    d
„|j ¡Dƒ}t|ƒrŒ| d d „|Dƒ¡}||S) a
        First discrete difference of element.
 
        Calculates the difference of each element compared with another
        element in the group (default is element in previous row).
 
        Parameters
        ----------
        periods : int, default 1
            Periods to shift for calculating difference, accepts negative values.
        axis : axis to shift, default 0
            Take difference over rows (0) or columns (1).
 
        Returns
        -------
        Series or DataFrame
            First differences.
        rcs|jˆˆdS)Nr')r\rÍ)r{r(rcrdr”r•zGroupBy.diff.<locals>.<lambda>r'roÚint16rºÚfloat32csg|]\}}|ˆkr|‘qSrcrc)rœÚcr9)Ú dtypes_to_f32rcrdrsz GroupBy.diff.<locals>.<listcomp>cSsi|]
}|d“qS)r-rc)rœr.rcrcrdÚ
<dictcomp>sz GroupBy.diff.<locals>.<dictcomp>)    rmr¯r)rír9r<ZdtypesÚitemsr‹)rbr(r{r‚ÚshiftedZ    to_coercerc)r{r/r(rdr\îs
 
 z GroupBy.diffrèr)r(Ú fill_methodr{c
sŒˆdk    sˆdkr6‡‡‡‡‡fdd„}|j||jddSˆdkrFd‰d‰t|ˆƒˆd}|j|jj|j|jd    }|jˆˆ|jd
}    ||    d S) z¿
        Calculate pct_change of each value to previous entry in group.
 
        Returns
        -------
        Series or DataFrame
            Percentage changes within each group.
        Nrcs|jˆˆˆˆˆdS)N)r(r3ràr+r{)Ú
pct_changerÍ©r{r3r+ràr(rcrdr”-s ûz$GroupBy.pct_change.<locals>.<lambda>Trrèré)r{r)r(r+r{rº)    r×r°rrr^r~Úcodesr{rr))
rbr(r3ràr+r{rkZfilledZfill_grpr2rcr5rdr4sÿzGroupBy.pct_changeé)ržr_cCs| td|ƒ¡}| |¡S)a‘
        Return first n rows of each group.
 
        Similar to ``.apply(lambda x: x.head(n))``, but it returns a subset of rows
        from the original DataFrame with original index and order preserved
        (``as_index`` flag is ignored).
 
        Parameters
        ----------
        n : int
            If positive: number of entries to include from start of each group.
            If negative: number of entries to exclude from end of each group.
 
        Returns
        -------
        Series or DataFrame
            Subset of original Series or DataFrame as determined by n.
        %(see_also)s
        Examples
        --------
 
        >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
        ...                   columns=['A', 'B'])
        >>> df.groupby('A').head(1)
           A  B
        0  1  2
        2  5  6
        >>> df.groupby('A').head(-1)
           A  B
        0  1  2
        N©ríÚslicerî©rbržrðrcrcrdÚhead@s#z GroupBy.headcCs,|r| t| dƒ¡}n
| g¡}| |¡S)a°
        Return last n rows of each group.
 
        Similar to ``.apply(lambda x: x.tail(n))``, but it returns a subset of rows
        from the original DataFrame with original index and order preserved
        (``as_index`` flag is ignored).
 
        Parameters
        ----------
        n : int
            If positive: number of entries to include from end of each group.
            If negative: number of entries to exclude from start of each group.
 
        Returns
        -------
        Series or DataFrame
            Subset of original Series or DataFrame as determined by n.
        %(see_also)s
        Examples
        --------
 
        >>> df = pd.DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]],
        ...                   columns=['A', 'B'])
        >>> df.groupby('A').tail(1)
           A  B
        1  a  2
        3  b  2
        >>> df.groupby('A').tail(-1)
           A  B
        1  a  2
        3  b  2
        Nr8r:rcrcrdÚtailfs$
z GroupBy.tailznpt.NDArray[np.bool_])rðr_cCsD|jjd}||dk@}|jdkr,|j|S|jjdd…|fSdS)a
        Return _selected_obj with mask applied to the correct axis.
 
        Parameters
        ----------
        mask : np.ndarray[bool]
            Boolean mask to apply.
 
        Returns
        -------
        Series or DataFrame
            Filtered _selected_obj.
        rràN)r~rær{r°r;)rbrðrrcrcrdrî‘s
 
 
zGroupBy._mask_selected_objr")rPr‚rr_c Cs2|jj}t|ƒdkr|S|jr"|Stdd„|Dƒƒs8|Sdd„|Dƒ}|jj}|dk    rj| |¡|dg}tj||d}|j    r†| 
¡}|j r²|j   |j¡|dd    d
|i}|jf|ŽStd d„t|ƒDƒƒ}    t|    ƒd kròt|    Ž\}
} |jt| ƒdd }| |jj¡j|d    |d}t|    ƒd kr&|j|
d}|jddS)aI
        If we have categorical groupers, then we might want to make sure that
        we have a fully re-indexed output to the levels. This means expanding
        the output space to accommodate all values in the cartesian product of
        our groups, regardless of whether they were observed in the data or
        not. This will expand the output space if there are missing groups.
 
        The method returns early without modifying the input if the number of
        groupings is less than 2, self.observed == True or none of the groupers
        are categorical.
 
        Parameters
        ----------
        output : Series or DataFrame
            Object resulting from grouping and applying an operation.
        fill_value : scalar, default np.NaN
            Value to use for unobserved categories if self.observed is False.
        qs : np.ndarray[float64] or None, default None
            quantile values, only relevant for quantile.
 
        Returns
        -------
        Series or DataFrame
            Object (potentially) re-indexed to include all possible groups.
        rºcss|]}t|jttfƒVqdSr`)r–r¢r=rLr£rcrcrdrŸÒsÿz*GroupBy._reindex_output.<locals>.<genexpr>cSsg|]
}|j‘qSrc)Z group_indexr£rcrcrdrØsz+GroupBy._reindex_output.<locals>.<listcomp>Nr¥râFr‚css"|]\}}|jr||jfVqdSr`r›)rœrâr¤rcrcrdrŸ÷sr)rïr{)râr‚)rT)Údrop)r~rýr‹rƒrlr©ÚappendrNr«r„r¬rzr‚Z_get_axis_namer{rìr½r©r¡r=Z    set_indexrãr­) rbrPr‚rrýr¯r©rêÚdZ in_axis_grpsZg_numsZg_namesrcrcrdr¨sP  þ
 
 ý ÿ  ÿ zGroupBy._reindex_outputz
int | Nonez float | NonezSequence | Series | NonezRandomState | None)ržÚfracÚreplaceÚweightsÚ random_statecCsì|jjr|jSt |||¡}|dk    r8tj|j||jd}t |¡}|j     |j|j¡}g}    |D]r\}
} |j
|
} t | ƒ} |dk    r„|}n|dk    st ‚t || ƒ}tj| |||dkr²dn|| |d}|     | |¡q\t |    ¡}    |jj|    |jdS)aƒ
        Return a random sample of items from each group.
 
        You can use `random_state` for reproducibility.
 
        .. versionadded:: 1.1.0
 
        Parameters
        ----------
        n : int, optional
            Number of items to return for each group. Cannot be used with
            `frac` and must be no larger than the smallest group unless
            `replace` is True. Default is one if `frac` is None.
        frac : float, optional
            Fraction of items to return. Cannot be used with `n`.
        replace : bool, default False
            Allow or disallow sampling of the same row more than once.
        weights : list-like, optional
            Default None results in equal probability weighting.
            If passed a list-like then values must have the same length as
            the underlying DataFrame or Series object and will be used as
            sampling probabilities after normalization within each group.
            Values must be non-negative with at least one positive element
            within each group.
        random_state : int, array-like, BitGenerator, np.random.RandomState, np.random.Generator, optional
            If int, array-like, or BitGenerator, seed for random number generator.
            If np.random.RandomState or np.random.Generator, use as given.
 
            .. versionchanged:: 1.4.0
 
                np.random.Generator objects now accepted
 
        Returns
        -------
        Series or DataFrame
            A new object of same type as caller containing items randomly
            sampled within each group from the caller object.
 
        See Also
        --------
        DataFrame.sample: Generate random samples from a DataFrame object.
        numpy.random.choice: Generate a random sample from a given 1-D numpy
            array.
 
        Examples
        --------
        >>> df = pd.DataFrame(
        ...     {"a": ["red"] * 2 + ["blue"] * 2 + ["black"] * 2, "b": range(6)}
        ... )
        >>> df
               a  b
        0    red  0
        1    red  1
        2   blue  2
        3   blue  3
        4  black  4
        5  black  5
 
        Select one row at random for each distinct value in column a. The
        `random_state` argument can be used to guarantee reproducibility:
 
        >>> df.groupby("a").sample(n=1, random_state=1)
               a  b
        4  black  4
        2   blue  2
        1    red  1
 
        Set `frac` to sample fixed proportions rather than counts:
 
        >>> df.groupby("a")["b"].sample(frac=0.5, random_state=2)
        5    5
        2    2
        0    0
        Name: b, dtype: int64
 
        Control sample probabilities within groups by setting weights:
 
        >>> df.groupby("a").sample(
        ...     n=1,
        ...     weights=[1, 1, 1, 0, 0, 1],
        ...     random_state=1,
        ... )
               a  b
        5  black  5
        2   blue  2
        0    red  0
        Nr¸)rªrArBrC)r°rTr9Zprocess_sampling_sizeZpreprocess_weightsr{rµrCr~r¼r‘r‹rÇÚroundr>r˜rSrë)rbržr@rArBrCrªZ weights_arrZgroup_iteratorZsampled_indicesrïr‚Z grp_indicesZ
group_sizeZ sample_sizeZ
grp_samplercrcrdr9
s:`ÿ
 
  û
zGroupBy.sample) NrNNNNTTTFT)FF)N)FF)NFF)Frà)Frà)Fr)T)T)T)Fr„N)F)rºNNF)rºNNF)NFTFT)rºF)FrNN)Fr)FràNN)FràNN)Frà)Frà)NNN)N)N)N)N)rñròF)T)T)rTrFr)r)r)rF)rF)FFNNr)rºNrN)rºr)rºrèNNr)r7)r7)NNFNN)XrlrvrwrxrÀrrerurÛrÝrôrÙrrrr    r rrrrr(Ú _apply_docsÚformatrmr×r6r>r4rKrOrNrYrfrÁrgrzr)Ú_common_see_alsorlr"rbr†r‹r•r—r°r¶rªr+Ú_groupby_agg_method_templater¦r»r¼rÀrÄrÈrÊrDrÓrÖrÙrÚrÛrçrèrÞrìrðrrrr rr]rrrxr)r\r4r;r<rîr˜ÚNaNrr9rcrcrcrdr\:s2
Có*0
(ü=
ý-û !#'ÿÿ/ú-ý,û(ÿ#
'&*üVûPû<ú+ûûûE:%ü%
e  U]ý@üYR9ú _ÿÿø    ,&ú&#(üaúr\TrEr†rrÅrˆ)r‚Úbyr{r~rr_cCsXt|tƒrddlm}|}n*t|tƒr8ddlm}|}ntd|›ƒ‚||||||dS)Nr)Ú SeriesGroupBy)ÚDataFrameGroupByzinvalid type: )r‚r€r{r~r)r–rRZpandas.core.groupby.genericrKrDrLr')r‚rJr{r~rrKr²rLrcrcrdÚ get_groupbyŽs    
 
 ûrMrMznpt.NDArray[np.float64]rN)rŸrr_csˆt|ƒ‰|jrvtt|ƒ}t|ƒ ¡\}}t|jƒ|g}‡fdd„|jDƒt     
|t|ƒ¡g}t|||j dgd}nt  ||g¡}|S)a
    Insert the sequence 'qs' of quantiles as the inner-most level of a MultiIndex.
 
    The quantile level in the MultiIndex is a repeated copy of 'qs'.
 
    Parameters
    ----------
    idx : Index
    qs : np.ndarray[float64]
 
    Returns
    -------
    MultiIndex
    csg|]}t |ˆ¡‘qSrc)r˜r^)rœrΩrrcrdrÀsz*_insert_quantile_level.<locals>.<listcomp>N)rßr6r©) r‹Z    _is_multirrNrMZ    factorizer½rßr6r˜rVr©r«)rŸrZ    lev_codesrÿrßr6ÚmircrNrdr«s
&r)NrNT)‘rxÚ
__future__rr—Ú    functoolsrrrÓÚtextwraprÚtypingrrrr    r
r r r rrrrrr#Únumpyr˜Zpandas._config.configrZ pandas._libsrrZpandas._libs.algosrZpandas._libs.groupbyZ_libsr^ryZpandas._libs.missingrZpandas._typingrrrrrrrrr r!r"r#r$Zpandas.compat.numpyr%rZ pandas.errorsr&r'Zpandas.util._decoratorsr(r)r*r+Zpandas.core.dtypes.castr,Zpandas.core.dtypes.commonr-r.r/r0r1r2r3r4r5Zpandas.core.dtypes.missingr6r7Z pandas.corer8r9Zpandas.core._numbar:Zpandas.core.arraysr;r<r=r>r?r@rAZpandas.core.baserBrCZpandas.core.commonÚcoreÚcommonrµZpandas.core.framerDZpandas.core.genericrEZpandas.core.groupbyrFrGrHZpandas.core.groupby.grouperrIZpandas.core.groupby.indexingrJrKZpandas.core.indexes.apirLrMrNrOrPZpandas.core.internals.blocksrQZpandas.core.seriesrRZpandas.core.sortingrSZpandas.core.util.numba_rTrUrØrVrWrXrGrErHrÂZ_transform_templateZ _agg_templater[Z _KeysArgTyperyrÃr\rMrrcrcrcrdÚ<module>s¼  <   <  ,  $              5A‰-3bS 
üÿ    T nû