Skip to content

Commit

Permalink
DOC: add examples to groupby.first
Browse files Browse the repository at this point in the history
  • Loading branch information
Moisan committed Apr 13, 2022
1 parent f976aa6 commit 2810d09
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,8 +2302,7 @@ def first(self, numeric_only: bool = False, min_count: int = -1):
Parameters
----------
numeric_only : bool, default False
Include only float, int, boolean columns. If None, will attempt to use
everything, then use only numeric data.
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.
Expand All @@ -2323,12 +2322,24 @@ def first(self, numeric_only: bool = False, min_count: int = -1):
Examples
--------
>>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[None, 5, 6], C=[1, 2, 3]))
>>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[2, 2, None],
... C=['3/11/2000', '3/12/2000', '3/13/2000']))
>>> df['C'] = pd.to_datetime(df['C'])
>>> df.groupby("A").first()
B C
B C
A
1 5.0 1
3 6.0 3
1 2.0 2000-03-11
3 NaN 2000-03-13
>>> df.groupby("A").first(min_count=2)
B C
A
1 2.0 2000-03-11
3 NaN NaT
>>> df.groupby("A").first(numeric_only=True)
B
A
1 2.0
3 NaN
"""

def first_compat(obj: NDFrameT, axis: int = 0):
Expand Down

0 comments on commit 2810d09

Please sign in to comment.