Skip to content

Commit 33593a4

Browse files
authored
lreshape and wide_to_long documentation (Closes #33417) (#33418)
1 parent ddf4f24 commit 33593a4

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

pandas/core/frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -6609,6 +6609,8 @@ def groupby(
66096609
duplicate values for one index/column pair.
66106610
DataFrame.unstack : Pivot based on the index values instead of a
66116611
column.
6612+
wide_to_long : Wide panel to long format. Less flexible but more
6613+
user-friendly than melt.
66126614
66136615
Notes
66146616
-----
@@ -6763,6 +6765,10 @@ def pivot(self, index=None, columns=None, values=None) -> "DataFrame":
67636765
--------
67646766
DataFrame.pivot : Pivot without aggregation that can handle
67656767
non-numeric data.
6768+
DataFrame.melt: Unpivot a DataFrame from wide to long format,
6769+
optionally leaving identifiers set.
6770+
wide_to_long : Wide panel to long format. Less flexible but more
6771+
user-friendly than melt.
67666772
67676773
Examples
67686774
--------

pandas/core/reshape/melt.py

+44-7
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,43 @@ def melt(
144144
@deprecate_kwarg(old_arg_name="label", new_arg_name=None)
145145
def lreshape(data: "DataFrame", groups, dropna: bool = True, label=None) -> "DataFrame":
146146
"""
147-
Reshape long-format data to wide. Generalized inverse of DataFrame.pivot
147+
Reshape wide-format data to long. Generalized inverse of DataFrame.pivot.
148+
149+
Accepts a dictionary, ``groups``, in which each key is a new column name
150+
and each value is a list of old column names that will be "melted" under
151+
the new column name as part of the reshape.
148152
149153
Parameters
150154
----------
151155
data : DataFrame
156+
The wide-format DataFrame.
152157
groups : dict
153-
{new_name : list_of_columns}
154-
dropna : boolean, default True
158+
{new_name : list_of_columns}.
159+
dropna : bool, default True
160+
Do not include columns whose entries are all NaN.
161+
label : None
162+
Not used.
163+
164+
.. deprecated:: 1.0.0
165+
166+
Returns
167+
-------
168+
DataFrame
169+
Reshaped DataFrame.
170+
171+
See Also
172+
--------
173+
melt : Unpivot a DataFrame from wide to long format, optionally leaving
174+
identifiers set.
175+
pivot : Create a spreadsheet-style pivot table as a DataFrame.
176+
DataFrame.pivot : Pivot without aggregation that can handle
177+
non-numeric data.
178+
DataFrame.pivot_table : Generalization of pivot that can handle
179+
duplicate values for one index/column pair.
180+
DataFrame.unstack : Pivot based on the index values instead of a
181+
column.
182+
wide_to_long : Wide panel to long format. Less flexible but more
183+
user-friendly than melt.
155184
156185
Examples
157186
--------
@@ -169,10 +198,6 @@ def lreshape(data: "DataFrame", groups, dropna: bool = True, label=None) -> "Dat
169198
1 Yankees 2007 573
170199
2 Red Sox 2008 545
171200
3 Yankees 2008 526
172-
173-
Returns
174-
-------
175-
reshaped : DataFrame
176201
"""
177202
if isinstance(groups, dict):
178203
keys = list(groups.keys())
@@ -262,6 +287,18 @@ def wide_to_long(
262287
A DataFrame that contains each stub name as a variable, with new index
263288
(i, j).
264289
290+
See Also
291+
--------
292+
melt : Unpivot a DataFrame from wide to long format, optionally leaving
293+
identifiers set.
294+
pivot : Create a spreadsheet-style pivot table as a DataFrame.
295+
DataFrame.pivot : Pivot without aggregation that can handle
296+
non-numeric data.
297+
DataFrame.pivot_table : Generalization of pivot that can handle
298+
duplicate values for one index/column pair.
299+
DataFrame.unstack : Pivot based on the index values instead of a
300+
column.
301+
265302
Notes
266303
-----
267304
All extra variables are left untouched. This simply uses

0 commit comments

Comments
 (0)