-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Adding Multiindex support to dataframe pivot function(Fixes #21425) #21467
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
79dacb2
Adding Multiindex support to dataframe pivot function(Fixes #21425)
NikhilKumarM f95f854
added whatsnew entry in v0.23.2.txt file
NikhilKumarM 100a4bc
Added test case for testing dataframe pivot function with multile col…
NikhilKumarM ecc19d2
Made changes as per PEP8 requirements
NikhilKumarM 7f6c09c
changed the type of exp_columns to Index
NikhilKumarM 34fb002
Moved whatsnew entry from v0.23.2.txt to v0.24.0.txt
NikhilKumarM 787b289
Removed the comments that are not required
NikhilKumarM 358e0ea
corrected whatsnew entry
NikhilKumarM 811ab86
Changed indexes to list comprehension
NikhilKumarM 7b6b5a4
used is_list_like to check if input is list
NikhilKumarM 3bcfc16
resolving merge conflict in whatsnew
NikhilKumarM 0234b38
trying to solve merge conflict
NikhilKumarM a8f80ed
Merge branch 'master' into master
NikhilKumarM 7a050d6
Handling the case when there is no values argument in pivot func
NikhilKumarM beb768b
added one more test case for pivot function with multi column index
NikhilKumarM faab956
added whitespace to remove linting error
NikhilKumarM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,6 +283,23 @@ def test_pivot_multi_functions(self): | |
expected = concat([means, stds], keys=['mean', 'std'], axis=1) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_pivot_multiple_columns_as_index(self): | ||
# adding the test case for multiple columns as index (#21425) | ||
df = DataFrame({'lev1': [1, 1, 1, 1, 2, 2, 2, 2], | ||
'lev2': [1, 1, 2, 2, 1, 1, 2, 2], | ||
'lev3': [1, 2, 1, 2, 1, 2, 1, 2], | ||
'values': [0, 1, 2, 3, 4, 5, 6, 7]}) | ||
result = df.pivot(index=['lev1', 'lev2'], | ||
columns='lev3', | ||
values='values') | ||
exp_index = pd.MultiIndex.from_product([[1, 2], [1, 2]], | ||
names=['lev1', 'lev2']) | ||
exp_columns = Index([1, 2], name='lev3') | ||
expected = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], | ||
exp_index, | ||
exp_columns) | ||
tm.assert_frame_equal(result, expected) | ||
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. Can you add an example where the |
||
|
||
def test_pivot_index_with_nan(self): | ||
# GH 3588 | ||
nan = np.nan | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
is_list_like
instead hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will do it.