@@ -327,17 +327,18 @@ def select_rows(
327
327
return _select (df , rows = list (args ), invert = invert )
328
328
329
329
330
+ @pf .register_groupby_method
330
331
@pf .register_dataframe_method
331
332
@pf .register_series_method
332
333
@deprecated_alias (rows = "index" )
333
334
def select (
334
- df : pd .DataFrame | pd .Series ,
335
+ df : pd .DataFrame | pd .Series | DataFrameGroupBy ,
335
336
* args : tuple ,
336
337
index : Any = None ,
337
338
columns : Any = None ,
338
339
axis : str = "columns" ,
339
340
invert : bool = False ,
340
- ) -> pd .DataFrame | pd .Series :
341
+ ) -> pd .DataFrame | pd .Series | DataFrameGroupBy :
341
342
"""Method-chainable selection of rows and/or columns.
342
343
343
344
It accepts a string, shell-like glob strings `(*string*)`,
@@ -371,6 +372,8 @@ def select(
371
372
- `rows` keyword deprecated in favour of `index`.
372
373
- 0.31.0
373
374
- Add support for pd.Series.
375
+ - 0.32.0
376
+ - Add support for DataFrameGroupBy.
374
377
375
378
Examples:
376
379
>>> import pandas as pd
@@ -436,6 +439,10 @@ def select(
436
439
Returns:
437
440
A pandas DataFrame or Series with the specified rows and/or columns selected.
438
441
""" # noqa: E501
442
+ if args and isinstance (df , DataFrameGroupBy ):
443
+ return get_columns (group = df , label = list (args ))
444
+ if isinstance (df , DataFrameGroupBy ):
445
+ return get_columns (group = df , label = [columns ])
439
446
if args :
440
447
check ("invert" , invert , [bool ])
441
448
if (index is not None ) or (columns is not None ):
@@ -478,6 +485,12 @@ def get_index_labels(
478
485
return index [_select_index (arg , df , axis )]
479
486
480
487
488
+ @refactored_function (
489
+ message = (
490
+ "This function will be deprecated in a 1.x release. "
491
+ "Please use `jn.select` instead."
492
+ )
493
+ )
481
494
def get_columns (
482
495
group : DataFrameGroupBy | SeriesGroupBy , label : Any
483
496
) -> DataFrameGroupBy | SeriesGroupBy :
@@ -488,6 +501,11 @@ def get_columns(
488
501
489
502
!!! info "New in version 0.25.0"
490
503
504
+ !!!note
505
+
506
+ This function will be deprecated in a 1.x release.
507
+ Please use `jn.select` instead.
508
+
491
509
Args:
492
510
group: A Pandas GroupBy object.
493
511
label: column(s) to select.
0 commit comments