plydata.one_table_verbs.head

class plydata.one_table_verbs.head(*args, **kwargs)[source]

Select the top n rows

Parameters
datadataframe, optional

Useful when not using the >> operator.

nint, optional

Number of rows to return. If the data is grouped, then number of rows per group. Default is 5.

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({
...     'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
...     'y': list('aaaabbcddd') })
>>> df >> head(2)
   x  y
0  1  a
1  2  a

Grouped dataframe

>>> df >> group_by('y') >> head(2)
groups: ['y']
   x  y
0  1  a
1  2  a
2  5  b
3  6  b
4  7  c
5  8  d
6  9  d