Skip to content

Commit 2810d09

Browse files
committed
DOC: add examples to groupby.first
1 parent f976aa6 commit 2810d09

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pandas/core/groupby/groupby.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -2302,8 +2302,7 @@ def first(self, numeric_only: bool = False, min_count: int = -1):
23022302
Parameters
23032303
----------
23042304
numeric_only : bool, default False
2305-
Include only float, int, boolean columns. If None, will attempt to use
2306-
everything, then use only numeric data.
2305+
Include only float, int, boolean columns.
23072306
min_count : int, default -1
23082307
The required number of valid values to perform the operation. If fewer
23092308
than ``min_count`` non-NA values are present the result will be NA.
@@ -2323,12 +2322,24 @@ def first(self, numeric_only: bool = False, min_count: int = -1):
23232322
23242323
Examples
23252324
--------
2326-
>>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[None, 5, 6], C=[1, 2, 3]))
2325+
>>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[2, 2, None],
2326+
... C=['3/11/2000', '3/12/2000', '3/13/2000']))
2327+
>>> df['C'] = pd.to_datetime(df['C'])
23272328
>>> df.groupby("A").first()
2328-
B C
2329+
B C
23292330
A
2330-
1 5.0 1
2331-
3 6.0 3
2331+
1 2.0 2000-03-11
2332+
3 NaN 2000-03-13
2333+
>>> df.groupby("A").first(min_count=2)
2334+
B C
2335+
A
2336+
1 2.0 2000-03-11
2337+
3 NaN NaT
2338+
>>> df.groupby("A").first(numeric_only=True)
2339+
B
2340+
A
2341+
1 2.0
2342+
3 NaN
23322343
"""
23332344

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

0 commit comments

Comments
 (0)