@@ -2235,8 +2235,43 @@ def max(
2235
2235
)
2236
2236
2237
2237
@final
2238
- @doc ( _groupby_agg_method_template , fname = "first" , no = False , mc = - 1 )
2238
+ @Substitution ( name = "groupby" )
2239
2239
def first (self , numeric_only : bool = False , min_count : int = - 1 ):
2240
+ """
2241
+ Compute the first non-null entry of each column.
2242
+
2243
+ Parameters
2244
+ ----------
2245
+ numeric_only : bool, default False
2246
+ Include only float, int, boolean columns. If None, will attempt to use
2247
+ everything, then use only numeric data.
2248
+ min_count : int, default -1
2249
+ The required number of valid values to perform the operation. If fewer
2250
+ than ``min_count`` non-NA values are present the result will be NA.
2251
+
2252
+ Returns
2253
+ -------
2254
+ Series or DataFrame
2255
+ First non-null of values within each group.
2256
+
2257
+ See Also
2258
+ --------
2259
+ DataFrame.groupby : Apply a function groupby to each row or column of a
2260
+ DataFrame.
2261
+ DataFrame.core.groupby.GroupBy.last : Compute the last non-null entry of each
2262
+ column.
2263
+ DataFrame.core.groupby.GroupBy.nth : Take the nth row from each group.
2264
+
2265
+ Examples
2266
+ --------
2267
+ >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[None, 5, 6], C=[1, 2, 3]))
2268
+ >>> df.groupby("A").first()
2269
+ B C
2270
+ A
2271
+ 1 5.0 1
2272
+ 3 6.0 3
2273
+ """
2274
+
2240
2275
def first_compat (obj : NDFrameT , axis : int = 0 ):
2241
2276
def first (x : Series ):
2242
2277
"""Helper function for first item that isn't NA."""
@@ -2260,8 +2295,43 @@ def first(x: Series):
2260
2295
)
2261
2296
2262
2297
@final
2263
- @doc ( _groupby_agg_method_template , fname = "last" , no = False , mc = - 1 )
2298
+ @Substitution ( name = "groupby" )
2264
2299
def last (self , numeric_only : bool = False , min_count : int = - 1 ):
2300
+ """
2301
+ Compute the last non-null entry of each column.
2302
+
2303
+ Parameters
2304
+ ----------
2305
+ numeric_only : bool, default False
2306
+ Include only float, int, boolean columns. If None, will attempt to use
2307
+ everything, then use only numeric data.
2308
+ min_count : int, default -1
2309
+ The required number of valid values to perform the operation. If fewer
2310
+ than ``min_count`` non-NA values are present the result will be NA.
2311
+
2312
+ Returns
2313
+ -------
2314
+ Series or DataFrame
2315
+ Last non-null of values within each group.
2316
+
2317
+ See Also
2318
+ --------
2319
+ DataFrame.groupby : Apply a function groupby to each row or column of a
2320
+ DataFrame.
2321
+ DataFrame.core.groupby.GroupBy.first : Compute the first non-null entry of each
2322
+ column.
2323
+ DataFrame.core.groupby.GroupBy.nth : Take the nth row from each group.
2324
+
2325
+ Examples
2326
+ --------
2327
+ >>> df = pd.DataFrame(dict(A=[1, 1, 3], B=[5, None, 6], C=[1, 2, 3]))
2328
+ >>> df.groupby("A").last()
2329
+ B C
2330
+ A
2331
+ 1 5.0 2
2332
+ 3 6.0 3
2333
+ """
2334
+
2265
2335
def last_compat (obj : NDFrameT , axis : int = 0 ):
2266
2336
def last (x : Series ):
2267
2337
"""Helper function for last item that isn't NA."""
0 commit comments