Skip to content

Commit 1d017f2

Browse files
Backport PR #45612: DOC: Improve reshaping.rst (#45669)
Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 414d8f5 commit 1d017f2

File tree

8 files changed

+97
-90
lines changed

8 files changed

+97
-90
lines changed

doc/source/user_guide/reshaping.rst

+61-90
Large diffs are not rendered by default.

pandas/core/algorithms.py

+4
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ def factorize(
631631
cut : Discretize continuous-valued array.
632632
unique : Find the unique value in an array.
633633
634+
Notes
635+
-----
636+
Reference :ref:`the user guide <reshaping.factorize>` for more examples.
637+
634638
Examples
635639
--------
636640
These examples all show factorize as a top-level method like

pandas/core/frame.py

+14
Original file line numberDiff line numberDiff line change
@@ -7780,6 +7780,8 @@ def groupby(
77807780
For finer-tuned control, see hierarchical indexing documentation along
77817781
with the related stack/unstack methods.
77827782
7783+
Reference :ref:`the user guide <reshaping.pivot>` for more examples.
7784+
77837785
Examples
77847786
--------
77857787
>>> df = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two',
@@ -7938,6 +7940,10 @@ def pivot(self, index=None, columns=None, values=None) -> DataFrame:
79387940
wide_to_long : Wide panel to long format. Less flexible but more
79397941
user-friendly than melt.
79407942
7943+
Notes
7944+
-----
7945+
Reference :ref:`the user guide <reshaping.pivot>` for more examples.
7946+
79417947
Examples
79427948
--------
79437949
>>> df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
@@ -8094,6 +8100,8 @@ def stack(self, level: Level = -1, dropna: bool = True):
80948100
vertically on top of each other (in the index of the
80958101
dataframe).
80968102
8103+
Reference :ref:`the user guide <reshaping.stacking>` for more examples.
8104+
80978105
Examples
80988106
--------
80998107
**Single level columns**
@@ -8273,6 +8281,8 @@ def explode(
82738281
result in a np.nan for that row. In addition, the ordering of rows in the
82748282
output will be non-deterministic when exploding sets.
82758283
8284+
Reference :ref:`the user guide <reshaping.explode>` for more examples.
8285+
82768286
Examples
82778287
--------
82788288
>>> df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]],
@@ -8372,6 +8382,10 @@ def unstack(self, level: Level = -1, fill_value=None):
83728382
DataFrame.stack : Pivot a level of the column labels (inverse operation
83738383
from `unstack`).
83748384
8385+
Notes
8386+
-----
8387+
Reference :ref:`the user guide <reshaping.stacking>` for more examples.
8388+
83758389
Examples
83768390
--------
83778391
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),

pandas/core/reshape/pivot.py

+2
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ def crosstab(
589589
In the event that there aren't overlapping indexes an empty DataFrame will
590590
be returned.
591591
592+
Reference :ref:`the user guide <reshaping.crosstabulations>` for more examples.
593+
592594
Examples
593595
--------
594596
>>> a = np.array(["foo", "foo", "foo", "foo", "bar", "bar",

pandas/core/reshape/reshape.py

+4
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ def get_dummies(
857857
--------
858858
Series.str.get_dummies : Convert Series to dummy codes.
859859
860+
Notes
861+
-----
862+
Reference :ref:`the user guide <reshaping.dummies>` for more examples.
863+
860864
Examples
861865
--------
862866
>>> s = pd.Series(list('abca'))

pandas/core/reshape/tile.py

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def cut(
145145
Any NA values will be NA in the result. Out of bounds values will be NA in
146146
the resulting Series or Categorical object.
147147
148+
Reference :ref:`the user guide <reshaping.tile.cut>` for more examples.
149+
148150
Examples
149151
--------
150152
Discretize into three equal-sized bins.

pandas/core/series.py

+6
Original file line numberDiff line numberDiff line change
@@ -4078,6 +4078,8 @@ def explode(self, ignore_index: bool = False) -> Series:
40784078
result in a np.nan for that row. In addition, the ordering of elements in
40794079
the output will be non-deterministic when exploding sets.
40804080
4081+
Reference :ref:`the user guide <reshaping.explode>` for more examples.
4082+
40814083
Examples
40824084
--------
40834085
>>> s = pd.Series([[1, 2, 3], 'foo', [], [3, 4]])
@@ -4127,6 +4129,10 @@ def unstack(self, level=-1, fill_value=None) -> DataFrame:
41274129
DataFrame
41284130
Unstacked Series.
41294131
4132+
Notes
4133+
-----
4134+
Reference :ref:`the user guide <reshaping.stacking>` for more examples.
4135+
41304136
Examples
41314137
--------
41324138
>>> s = pd.Series([1, 2, 3, 4],

pandas/core/shared_docs.py

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@
195195
DataFrame.explode : Explode a DataFrame from list-like
196196
columns to long format.
197197
198+
Notes
199+
-----
200+
Reference :ref:`the user guide <reshaping.melt>` for more examples.
201+
198202
Examples
199203
--------
200204
>>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'},

0 commit comments

Comments
 (0)