Skip to content

Commit 6479529

Browse files
DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.hist (#57304)
* DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.hist * update example for df.groupby().hist()
1 parent dd2bbc9 commit 6479529

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
140140
pandas.core.groupby.DataFrameGroupBy.rolling\
141141
pandas.core.groupby.SeriesGroupBy.nth\
142142
pandas.core.groupby.SeriesGroupBy.rolling\
143-
pandas.core.groupby.DataFrameGroupBy.hist\
144143
pandas.core.groupby.DataFrameGroupBy.plot\
145144
pandas.core.groupby.SeriesGroupBy.plot # There should be no backslash in the final line, please keep this comment in the last ignored function
146145
RET=$(($RET + $?)) ; echo $MSG "DONE"

pandas/core/groupby/generic.py

+86-1
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,6 @@ def cov(
25952595
)
25962596
return result
25972597

2598-
@doc(DataFrame.hist.__doc__)
25992598
def hist(
26002599
self,
26012600
column: IndexLabel | None = None,
@@ -2615,6 +2614,92 @@ def hist(
26152614
legend: bool = False,
26162615
**kwargs,
26172616
):
2617+
"""
2618+
Make a histogram of the DataFrame's columns.
2619+
2620+
A `histogram`_ is a representation of the distribution of data.
2621+
This function calls :meth:`matplotlib.pyplot.hist`, on each series in
2622+
the DataFrame, resulting in one histogram per column.
2623+
2624+
.. _histogram: https://en.wikipedia.org/wiki/Histogram
2625+
2626+
Parameters
2627+
----------
2628+
column : str or sequence, optional
2629+
If passed, will be used to limit data to a subset of columns.
2630+
by : object, optional
2631+
If passed, then used to form histograms for separate groups.
2632+
grid : bool, default True
2633+
Whether to show axis grid lines.
2634+
xlabelsize : int, default None
2635+
If specified changes the x-axis label size.
2636+
xrot : float, default None
2637+
Rotation of x axis labels. For example, a value of 90 displays the
2638+
x labels rotated 90 degrees clockwise.
2639+
ylabelsize : int, default None
2640+
If specified changes the y-axis label size.
2641+
yrot : float, default None
2642+
Rotation of y axis labels. For example, a value of 90 displays the
2643+
y labels rotated 90 degrees clockwise.
2644+
ax : Matplotlib axes object, default None
2645+
The axes to plot the histogram on.
2646+
sharex : bool, default True if ax is None else False
2647+
In case subplots=True, share x axis and set some x axis labels to
2648+
invisible; defaults to True if ax is None otherwise False if an ax
2649+
is passed in.
2650+
Note that passing in both an ax and sharex=True will alter all x axis
2651+
labels for all subplots in a figure.
2652+
sharey : bool, default False
2653+
In case subplots=True, share y axis and set some y axis labels to
2654+
invisible.
2655+
figsize : tuple, optional
2656+
The size in inches of the figure to create. Uses the value in
2657+
`matplotlib.rcParams` by default.
2658+
layout : tuple, optional
2659+
Tuple of (rows, columns) for the layout of the histograms.
2660+
bins : int or sequence, default 10
2661+
Number of histogram bins to be used. If an integer is given, bins + 1
2662+
bin edges are calculated and returned. If bins is a sequence, gives
2663+
bin edges, including left edge of first bin and right edge of last
2664+
bin. In this case, bins is returned unmodified.
2665+
2666+
backend : str, default None
2667+
Backend to use instead of the backend specified in the option
2668+
``plotting.backend``. For instance, 'matplotlib'. Alternatively, to
2669+
specify the ``plotting.backend`` for the whole session, set
2670+
``pd.options.plotting.backend``.
2671+
2672+
legend : bool, default False
2673+
Whether to show the legend.
2674+
2675+
**kwargs
2676+
All other plotting keyword arguments to be passed to
2677+
:meth:`matplotlib.pyplot.hist`.
2678+
2679+
Returns
2680+
-------
2681+
matplotlib.Axes or numpy.ndarray of them
2682+
2683+
See Also
2684+
--------
2685+
matplotlib.pyplot.hist : Plot a histogram using matplotlib.
2686+
2687+
Examples
2688+
--------
2689+
This example draws a histogram based on the length and width of
2690+
some animals, displayed in three bins
2691+
2692+
.. plot::
2693+
:context: close-figs
2694+
2695+
>>> data = {
2696+
... "length": [1.5, 0.5, 1.2, 0.9, 3],
2697+
... "width": [0.7, 0.2, 0.15, 0.2, 1.1],
2698+
... }
2699+
>>> index = ["pig", "rabbit", "duck", "chicken", "horse"]
2700+
>>> df = pd.DataFrame(data, index=index)
2701+
>>> hist = df.groupby("length").hist(bins=3)
2702+
"""
26182703
result = self._op_via_apply(
26192704
"hist",
26202705
column=column,

0 commit comments

Comments
 (0)