Skip to content

DOC: Improve reshaping.rst #45612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 28, 2022
151 changes: 61 additions & 90 deletions doc/source/user_guide/reshaping.rst

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ def factorize(
cut : Discretize continuous-valued array.
unique : Find the unique value in an array.

Notes
-----
Reference :ref:`the user guide <reshaping.factorize>` for more examples.

Examples
--------
These examples all show factorize as a top-level method like
Expand Down
14 changes: 14 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7792,6 +7792,8 @@ def groupby(
For finer-tuned control, see hierarchical indexing documentation along
with the related stack/unstack methods.

Reference :ref:`the user guide <reshaping.pivot>` for more examples.

Examples
--------
>>> df = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two',
Expand Down Expand Up @@ -7950,6 +7952,10 @@ def pivot(self, index=None, columns=None, values=None) -> DataFrame:
wide_to_long : Wide panel to long format. Less flexible but more
user-friendly than melt.

Notes
-----
Reference :ref:`the user guide <reshaping.pivot>` for more examples.

Examples
--------
>>> df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
Expand Down Expand Up @@ -8106,6 +8112,8 @@ def stack(self, level: Level = -1, dropna: bool = True):
vertically on top of each other (in the index of the
dataframe).

Reference :ref:`the user guide <reshaping.stacking>` for more examples.

Examples
--------
**Single level columns**
Expand Down Expand Up @@ -8285,6 +8293,8 @@ def explode(
result in a np.nan for that row. In addition, the ordering of rows in the
output will be non-deterministic when exploding sets.

Reference :ref:`the user guide <reshaping.explode>` for more examples.

Examples
--------
>>> df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]],
Expand Down Expand Up @@ -8384,6 +8394,10 @@ def unstack(self, level: Level = -1, fill_value=None):
DataFrame.stack : Pivot a level of the column labels (inverse operation
from `unstack`).

Notes
-----
Reference :ref:`the user guide <reshaping.stacking>` for more examples.

Examples
--------
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ def crosstab(
In the event that there aren't overlapping indexes an empty DataFrame will
be returned.

Reference :ref:`the user guide <reshaping.crosstabulations>` for more examples.

Examples
--------
>>> a = np.array(["foo", "foo", "foo", "foo", "bar", "bar",
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@ def get_dummies(
--------
Series.str.get_dummies : Convert Series to dummy codes.

Notes
-----
Reference :ref:`the user guide <reshaping.dummies>` for more examples.

Examples
--------
>>> s = pd.Series(list('abca'))
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/reshape/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def cut(
Any NA values will be NA in the result. Out of bounds values will be NA in
the resulting Series or Categorical object.

Reference :ref:`the user guide <reshaping.tile.cut>` for more examples.

Examples
--------
Discretize into three equal-sized bins.
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,8 @@ def explode(self, ignore_index: bool = False) -> Series:
result in a np.nan for that row. In addition, the ordering of elements in
the output will be non-deterministic when exploding sets.

Reference :ref:`the user guide <reshaping.explode>` for more examples.

Examples
--------
>>> s = pd.Series([[1, 2, 3], 'foo', [], [3, 4]])
Expand Down Expand Up @@ -4132,6 +4134,10 @@ def unstack(self, level=-1, fill_value=None) -> DataFrame:
DataFrame
Unstacked Series.

Notes
-----
Reference :ref:`the user guide <reshaping.stacking>` for more examples.

Examples
--------
>>> s = pd.Series([1, 2, 3, 4],
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/shared_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
DataFrame.explode : Explode a DataFrame from list-like
columns to long format.

Notes
-----
Reference :ref:`the user guide <reshaping.melt>` for more examples.

Examples
--------
>>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'},
Expand Down