API ref missing DataFrameGroupBy objects?

Looking at the API documentation , I cannot find class methods DataFrameGroupBy. I wonder if I was looking for a place elsewhere.

According to the manual, these objects have the following methods:

In [22]: gb = df.groupby('gender')
In [23]: gb.<TAB>
gb.agg        gb.boxplot    gb.cummin     gb.describe   gb.filter     gb.get_group  gb.height     gb.last       gb.median     gb.ngroups    gb.plot       gb.rank       gb.std        gb.transform
gb.aggregate  gb.count      gb.cumprod    gb.dtype      gb.first      gb.groups     gb.hist       gb.max        gb.min        gb.nth        gb.prod       gb.resample   gb.sum        gb.var
gb.apply      gb.cummax     gb.cumsum     gb.fillna     gb.gender     gb.head       gb.indices    gb.mean       gb.name       gb.ohlc       gb.quantile   gb.size       gb.tail       gb.weight

Where cna i find an explanation of what they do?

+4
source share
1 answer

The easiest way to find out what a function does is to call docstring:

In [24]: gb.filter?  # help(gb.filter) in python interpreter
Type:       instancemethod
String Form:<bound method DataFrameGroupBy.filter of <pandas.core.groupby.DataFrameGroupBy object at 0x1046ad290>>
File:       /Users/andy/pandas/pandas/core/groupby.py
Definition: g.filter(self, func, dropna=True, *args, **kwargs)
Docstring:
Return a copy of a DataFrame excluding elements from groups that
do not satisfy the boolean criterion specified by func.

Parameters
----------
f : function
    Function to apply to each subframe. Should return True or False.
dropna : Drop groups that do not pass the filter. True by default;
    if False, groups that evaluate False are filled with NaNs.

Notes
-----
Each subframe is endowed the attribute 'name' in case you need to know
which group you are working on.

Example
--------
>>> grouped = df.groupby(lambda x: mapping[x])
>>> grouped.filter(lambda x: x['A'].sum() + x['B'].sum() > 0)

However, there is an error that the methods “fail” do not show a valid docstring, but rather show only the wrapper for the DataFrame method that they call.

, gb.cummin(*args, **kwargs) gb.apply(lambda x: x.cummin(*args, **kwargs)).

In [31]: gb.cummin?
Type:       function
String Form:<function wrapper at 0x1046a9410>
File:       /Users/andy/pandas/pandas/core/groupby.py
Definition: g.cummin(*args, **kwargs)
Docstring:  <no docstring>

In [32]: df.cummin?
Type:       instancemethod
String Form:
<bound method DataFrame.min of    a  b
0  1  2

[1 rows x 2 columns]>
File:       /Users/andy/pandas/pandas/core/generic.py
Definition: df.cummin(self, axis=None, dtype=None, out=None, skipna=True, **kwargs)
Docstring:
Return cumulative min over requested axis.

Parameters
----------
axis : {index (0), columns (1)}
skipna : boolean, default True
    Exclude NA/null values. If an entire row/column is NA, the result
    will be NA

Returns
-------
min : Series

:

In [41]: df = pd.DataFrame([[2, 4], [1, 5], [2, 2], [1, 3]], columns=['a', 'b'])

In [42]: df
Out[42]:
   a  b
0  2  4
1  1  5
2  2  2
3  1  3

In [43]: gb = df.groupby('a')

In [44]: gb.cummin()
Out[44]:
   a  b
0  2  4
1  1  5
2  2  2
3  1  3

In [45]: gb.apply(lambda x: x.cummin())
Out[45]:
   a  b
0  2  4
1  1  5
2  2  2
3  1  3

. , ( , ), , , 0,14...

+5

Source: https://habr.com/ru/post/1526803/


All Articles