@@ -997,6 +997,83 @@ def expanding(self, *args, **kwargs):
997
997
"""
998
998
raise NotImplementedError (constants .ABSTRACT_METHOD_ERROR_MESSAGE )
999
999
1000
+ def head (self , n : int = 5 ):
1001
+ """
1002
+ Return last first n rows of each group
1003
+
1004
+ **Examples:**
1005
+
1006
+ >>> import bigframes.pandas as bpd
1007
+ >>> bpd.options.display.progress_bar = None
1008
+
1009
+ >>> df = bpd.DataFrame([[1, 2], [1, 4], [5, 6]],
1010
+ ... columns=['A', 'B'])
1011
+ >>> df.groupby('A').head(1)
1012
+ A B
1013
+ 0 1 2
1014
+ 2 5 6
1015
+ [2 rows x 2 columns]
1016
+
1017
+ Args:
1018
+ n (int):
1019
+ If positive: number of entries to include from start of each group.
1020
+ If negative: number of entries to exclude from end of each group.
1021
+
1022
+ Returns:
1023
+ bigframes.pandas.DataFrame or bigframes.pandas.Series:
1024
+ First n rows of the original DataFrame or Series
1025
+
1026
+ """
1027
+ raise NotImplementedError (constants .ABSTRACT_METHOD_ERROR_MESSAGE )
1028
+
1029
+ def size (self ):
1030
+ """
1031
+ Compute group sizes.
1032
+
1033
+ **Examples:**
1034
+
1035
+ For SeriesGroupBy:
1036
+
1037
+ >>> import bigframes.pandas as bpd
1038
+ >>> bpd.options.display.progress_bar = None
1039
+
1040
+ >>> lst = ['a', 'a', 'b']
1041
+ >>> ser = bpd.Series([1, 2, 3], index=lst)
1042
+ >>> ser
1043
+ a 1
1044
+ a 2
1045
+ b 3
1046
+ dtype: Int64
1047
+ >>> ser.groupby(level=0).size()
1048
+ a 2
1049
+ b 1
1050
+ dtype: Int64
1051
+
1052
+ For DataFrameGroupBy:
1053
+
1054
+ >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]]
1055
+ >>> df = bpd.DataFrame(data, columns=["a", "b", "c"],
1056
+ ... index=["owl", "toucan", "eagle"])
1057
+ >>> df
1058
+ a b c
1059
+ owl 1 2 3
1060
+ toucan 1 5 6
1061
+ eagle 7 8 9
1062
+ [3 rows x 3 columns]
1063
+ >>> df.groupby("a").size()
1064
+ a
1065
+ 1 2
1066
+ 7 1
1067
+ dtype: Int64
1068
+
1069
+ Returns:
1070
+ bigframes.pandas.DataFrame or bigframes.pandas.Series:
1071
+ Number of rows in each group as a Series if as_index is True
1072
+ or a DataFrame if as_index is False.
1073
+
1074
+ """
1075
+ raise NotImplementedError (constants .ABSTRACT_METHOD_ERROR_MESSAGE )
1076
+
1000
1077
1001
1078
class SeriesGroupBy (GroupBy ):
1002
1079
def agg (self , func ):
0 commit comments