Skip to content

Commit fd17cf6

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53575)
Added examples
1 parent 5591590 commit fd17cf6

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
263263
pandas.core.window.ewm.ExponentialMovingWindow.cov \
264264
pandas.api.indexers.BaseIndexer \
265265
pandas.api.indexers.VariableOffsetWindowIndexer \
266-
pandas.core.groupby.DataFrameGroupBy.ffill \
267-
pandas.core.groupby.DataFrameGroupBy.ohlc \
268266
pandas.core.groupby.SeriesGroupBy.fillna \
269-
pandas.core.groupby.SeriesGroupBy.ffill \
270-
pandas.core.groupby.SeriesGroupBy.nunique \
271-
pandas.core.groupby.SeriesGroupBy.ohlc \
272-
pandas.core.groupby.SeriesGroupBy.hist \
273-
pandas.core.groupby.DataFrameGroupBy.plot \
274-
pandas.core.groupby.SeriesGroupBy.plot \
275267
pandas.io.formats.style.Styler \
276268
pandas.io.formats.style.Styler.from_custom_template \
277269
pandas.io.formats.style.Styler.set_caption \

pandas/core/groupby/generic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
622622
-------
623623
Series
624624
Number of unique values within each group.
625+
626+
Examples
627+
--------
628+
629+
>>> lst = ['a', 'a', 'b', 'b']
630+
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
631+
>>> ser
632+
a 1
633+
a 2
634+
b 3
635+
b 3
636+
dtype: int64
637+
>>> ser.groupby(level=0).nunique()
638+
a 2
639+
b 1
640+
dtype: int64
625641
"""
626642
ids, _, _ = self.grouper.group_info
627643

pandas/core/groupby/groupby.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,6 +3107,50 @@ def ohlc(self) -> DataFrame:
31073107
-------
31083108
DataFrame
31093109
Open, high, low and close values within each group.
3110+
3111+
Examples
3112+
--------
3113+
3114+
For SeriesGroupBy:
3115+
3116+
>>> lst = ['SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC', 'SPX', 'CAC',]
3117+
>>> ser = pd.Series([3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 0.1, 0.5], index=lst)
3118+
>>> ser
3119+
SPX 3.4
3120+
CAC 9.0
3121+
SPX 7.2
3122+
CAC 5.2
3123+
SPX 8.8
3124+
CAC 9.4
3125+
SPX 0.1
3126+
CAC 0.5
3127+
dtype: float64
3128+
>>> ser.groupby(level=0).ohlc()
3129+
open high low close
3130+
CAC 9.0 9.4 0.5 0.5
3131+
SPX 3.4 8.8 0.1 0.1
3132+
3133+
For DataFrameGroupBy:
3134+
3135+
>>> data = {2022: [1.2, 2.3, 8.9, 4.5, 4.4, 3, 2 , 1],
3136+
... 2023: [3.4, 9.0, 7.2, 5.2, 8.8, 9.4, 8.2, 1.0]}
3137+
>>> df = pd.DataFrame(data, index=['SPX', 'CAC', 'SPX', 'CAC',
3138+
... 'SPX', 'CAC', 'SPX', 'CAC'])
3139+
>>> df
3140+
2022 2023
3141+
SPX 1.2 3.4
3142+
CAC 2.3 9.0
3143+
SPX 8.9 7.2
3144+
CAC 4.5 5.2
3145+
SPX 4.4 8.8
3146+
CAC 3.0 9.4
3147+
SPX 2.0 8.2
3148+
CAC 1.0 1.0
3149+
>>> df.groupby(level=0).ohlc()
3150+
2022 2023
3151+
open high low close open high low close
3152+
CAC 2.3 4.5 1.0 1.0 9.0 9.4 1.0 1.0
3153+
SPX 1.2 8.9 1.2 2.0 3.4 8.8 3.4 8.2
31103154
"""
31113155
if self.obj.ndim == 1:
31123156
obj = self._selected_obj
@@ -3561,6 +3605,26 @@ def ffill(self, limit: int | None = None):
35613605
35623606
Examples
35633607
--------
3608+
3609+
For SeriesGroupBy:
3610+
3611+
>>> key = [0, 0, 1, 1]
3612+
>>> ser = pd.Series([np.nan, 2, 3, np.nan], index=key)
3613+
>>> ser
3614+
0 NaN
3615+
0 2.0
3616+
1 3.0
3617+
1 NaN
3618+
dtype: float64
3619+
>>> ser.groupby(level=0).ffill()
3620+
0 NaN
3621+
0 2.0
3622+
1 3.0
3623+
1 3.0
3624+
dtype: float64
3625+
3626+
For DataFrameGroupBy:
3627+
35643628
>>> df = pd.DataFrame(
35653629
... {
35663630
... "key": [0, 0, 1, 1, 1],

pandas/plotting/_core.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ def hist_series(
9898
See Also
9999
--------
100100
matplotlib.axes.Axes.hist : Plot a histogram using matplotlib.
101+
102+
Examples
103+
--------
104+
105+
.. plot::
106+
:context: close-figs
107+
108+
>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
109+
>>> ser = pd.Series([1, 2, 2, 4, 6, 6], index=lst)
110+
>>> hist = ser.groupby(level=0).hist()
101111
"""
102112
plot_backend = _get_plot_backend(backend)
103113
return plot_backend.hist_series(
@@ -778,12 +788,23 @@ class PlotAccessor(PandasObject):
778788
779789
Examples
780790
--------
791+
For SeriesGroupBy:
781792
782793
.. plot::
783794
:context: close-figs
784795
785796
>>> ser = pd.Series([1, 2, 3, 3])
786797
>>> plot = ser.plot(kind='hist', title="My plot")
798+
799+
For DataFrameGroupBy:
800+
801+
.. plot::
802+
:context: close-figs
803+
804+
>>> df = pd.DataFrame({'length': [1.5, 0.5, 1.2, 0.9, 3],
805+
... 'width': [0.7, 0.2, 0.15, 0.2, 1.1]},
806+
... index=['pig', 'rabbit', 'duck', 'chicken', 'horse'])
807+
>>> plot = df.plot()
787808
"""
788809

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

0 commit comments

Comments
 (0)