Skip to content

Commit 1213a17

Browse files
authored
DOC: add examples to groupby.first (#46766)
1 parent da69aef commit 1213a17

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pandas/core/groupby/groupby.py

+14-3
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,8 +2322,20 @@ 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=[None, 5, 6], C=[1, 2, 3],
2326+
... D=['3/11/2000', '3/12/2000', '3/13/2000']))
2327+
>>> df['D'] = pd.to_datetime(df['D'])
23272328
>>> df.groupby("A").first()
2329+
B C D
2330+
A
2331+
1 5.0 1 2000-03-11
2332+
3 6.0 3 2000-03-13
2333+
>>> df.groupby("A").first(min_count=2)
2334+
B C D
2335+
A
2336+
1 NaN 1.0 2000-03-11
2337+
3 NaN NaN NaT
2338+
>>> df.groupby("A").first(numeric_only=True)
23282339
B C
23292340
A
23302341
1 5.0 1

0 commit comments

Comments
 (0)