Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.core.window.ewm.ExponentialMovingWindow.cov \
pandas.api.indexers.BaseIndexer \
pandas.api.indexers.VariableOffsetWindowIndexer \
pandas.core.groupby.DataFrameGroupBy.ffill \
pandas.core.groupby.DataFrameGroupBy.ohlc \
pandas.core.groupby.SeriesGroupBy.fillna \
pandas.core.groupby.SeriesGroupBy.ffill \
pandas.core.groupby.SeriesGroupBy.nunique \
pandas.core.groupby.SeriesGroupBy.ohlc \
pandas.core.groupby.SeriesGroupBy.hist \
pandas.core.groupby.DataFrameGroupBy.plot \
pandas.core.groupby.SeriesGroupBy.plot \
pandas.io.formats.style.Styler \
pandas.io.formats.style.Styler.from_custom_template \
pandas.io.formats.style.Styler.set_caption \
Expand Down
16 changes: 16 additions & 0 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
-------
Series
Number of unique values within each group.

Examples
--------

>>> lst = ['a', 'a', 'b', 'b']
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
>>> ser
a 1
a 2
b 3
b 3
dtype: int64
>>> ser.groupby(level=0).nunique()
a 2
b 1
dtype: int64
"""
ids, _, _ = self.grouper.group_info

Expand Down
64 changes: 64 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,50 @@ def ohlc(self) -> DataFrame:
-------
DataFrame
Open, high, low and close values within each group.

Examples
--------

For SeriesGroupBy:

>>> lst = ['SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC',]
>>> ser = pd.Series([3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 0.1, 0.5], index=lst)
>>> ser
SPX 3.4
CAC 9.0
SPX 7.2
CAC 5.2
SPX 8.8
CAC 9.4
SPX 0.1
CAC 0.5
dtype: float64
>>> ser.groupby(level=0).ohlc()
open high low close
CAC 9.0 9.4 0.5 0.5
SPX 3.4 8.8 0.1 0.1

For DataFrameGroupBy:

>>> data = {2022: [1.2, 2.3, 8.9, 4.5, 4.4, 3, 2 , 1],
... 2023: [3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 8.2, 1.0]}
>>> df = pd.DataFrame(data, index=['SPX', 'CAC', 'SPX', 'CAC',
... 'SPX', 'CAC', 'SPX', 'CAC'])
>>> df
2022 2023
SPX 1.2 3.4
CAC 2.3 9.0
SPX 8.9 7.2
CAC 4.5 5.2
SPX 4.4 8.8
CAC 3.0 9.4
SPX 2.0 8.2
CAC 1.0 1.0
>>> df.groupby(level=0).ohlc()
2022 2023
open high low close open high low close
CAC 2.3 4.5 1.0 1.0 9.0 9.4 1.0 1.0
SPX 1.2 8.9 1.2 2.0 3.4 8.8 3.4 8.2
"""
if self.obj.ndim == 1:
obj = self._selected_obj
Expand Down Expand Up @@ -3561,6 +3605,26 @@ def ffill(self, limit: int | None = None):

Examples
--------

For SeriesGroupBy:

>>> key = [0, 0, 1, 1]
>>> ser = pd.Series([np.nan, 2, 3, np.nan], index=key)
>>> ser
0 NaN
0 2.0
1 3.0
1 NaN
dtype: float64
>>> ser.groupby(level=0).ffill()
0 NaN
0 2.0
1 3.0
1 3.0
dtype: float64

For DataFrameGroupBy:

>>> df = pd.DataFrame(
... {
... "key": [0, 0, 1, 1, 1],
Expand Down
21 changes: 21 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ def hist_series(
See Also
--------
matplotlib.axes.Axes.hist : Plot a histogram using matplotlib.

Examples
--------

.. plot::
:context: close-figs

>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
>>> ser = pd.Series([1, 2, 2, 4, 6, 6], index=lst)
>>> hist = ser.groupby(level=0).hist()
"""
plot_backend = _get_plot_backend(backend)
return plot_backend.hist_series(
Expand Down Expand Up @@ -778,12 +788,23 @@ class PlotAccessor(PandasObject):

Examples
--------
For SeriesGroupBy:

.. plot::
:context: close-figs

>>> ser = pd.Series([1, 2, 3, 3])
>>> plot = ser.plot(kind='hist', title="My plot")

For DataFrameGroupBy:

.. plot::
:context: close-figs

>>> df = pd.DataFrame({'length': [1.5, 0.5, 1.2, 0.9, 3],
... 'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
... index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
>>> plot = df.plot()
"""

_common_kinds = ("line", "bar", "barh", "kde", "density", "area", "hist", "box")
Expand Down