mars.dataframe.groupby.GroupBy.head¶
- GroupBy.head(n=5)¶
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 Series or DataFrame with original index and order preserved (as_indexflag is ignored).Does not work for negative values of n.
See also
Series.groupby,DataFrame.groupbyExamples
>>> import mars.dataframe as md >>> df = md.DataFrame([[1, 2], [1, 4], [5, 6]], ... columns=['A', 'B']) >>> df.groupby('A').head(1).execute() A B 0 1 2 2 5 6 >>> df.groupby('A').head(-1).execute() Empty DataFrame Columns: [A, B] Index: []