-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix incorrect example in wide_to_long docstring #25736
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
Changes from 7 commits
d472c17
5bda59c
26a28d5
cda32f0
aebff33
87a0867
e7b1679
b182905
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,8 +267,8 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): | |
With multiple id columns | ||
|
||
>>> df = pd.DataFrame({ | ||
... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], | ||
... 'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3], | ||
... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], | ||
... 'ht1': [2.8, 2.9, 2.2, 2, 1.8, 1.9, 2.2, 2.3, 2.1], | ||
... 'ht2': [3.4, 3.8, 2.9, 3.2, 2.8, 2.4, 3.3, 3.4, 2.9] | ||
... }) | ||
|
@@ -333,14 +333,10 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): | |
... 'X' : np.random.randint(3, size=3)}) | ||
>>> df['id'] = df.index | ||
>>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS | ||
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... | ||
0 0.548814 0.544883 0.437587 ... | ||
1 0.715189 0.423655 0.891773 ... | ||
2 0.602763 0.645894 0.963663 ... | ||
X id | ||
0 0 0 | ||
1 1 1 | ||
2 1 2 | ||
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... X id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the output too wide to include all the columns without any ellipses? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes @TomAugspurger the line is too wide to include all columns, so deleted only "B(quarterly)-2011" column (88 > 79 chars on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm, that's a little unfortunate as all the columns are important :/ Well, for now, let's use ellipses. FYI, your spacing is just slightly off, so it failed again :) diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py
index cec4c609c..df144db50 100644
--- a/pandas/core/reshape/melt.py
+++ b/pandas/core/reshape/melt.py
@@ -334,9 +334,9 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'):
>>> df['id'] = df.index
>>> df # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
A(quarterly)-2010 A(quarterly)-2011 B(quarterly)-2010 ... X id
- 0 0.548814 0.544883 0.437587 ... 0 0
- 1 0.715189 0.423655 0.891773 ... 1 1
- 2 0.602763 0.645894 0.963663 ... 2 2
+ 0 0.548814 0.544883 0.437587 ... 0 0
+ 1 0.715189 0.423655 0.891773 ... 1 1
+ 2 0.602763 0.645894 0.963663 ... 1 2
>>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id',
... j='year', sep='-')
I think you need an extra space so that the values in |
||
0 0.548814 0.544883 0.437587 ... 0 0 | ||
1 0.715189 0.423655 0.891773 ... 1 1 | ||
2 0.602763 0.645894 0.963663 ... 2 2 | ||
|
||
>>> pd.wide_to_long(df, ['A(quarterly)', 'B(quarterly)'], i='id', | ||
... j='year', sep='-') | ||
|
@@ -368,8 +364,8 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): | |
have non-integers as suffixes. | ||
|
||
>>> df = pd.DataFrame({ | ||
... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], | ||
... 'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3], | ||
... 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], | ||
... 'ht_one': [2.8, 2.9, 2.2, 2, 1.8, 1.9, 2.2, 2.3, 2.1], | ||
... 'ht_two': [3.4, 3.8, 2.9, 3.2, 2.8, 2.4, 3.3, 3.4, 2.9] | ||
... }) | ||
|
@@ -386,9 +382,9 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix=r'\d+'): | |
8 3 3 2.1 2.9 | ||
|
||
>>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age', | ||
sep='_', suffix='\w') | ||
... sep='_', suffix='\w+') | ||
>>> l | ||
... # doctest: +NORMALIZE_WHITESPACE | ||
... # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS | ||
ht | ||
famid birth age | ||
1 1 one 2.8 | ||
|
Uh oh!
There was an error while loading. Please reload this page.