-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
QST:Why DataFrame.pivot() will change the order of the rows of DataFrame? #39143
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
Comments
Hi, thanks for your question. Could you provide something reproducible? |
test = pd.DataFrame({'indus':['12.文教、工美、体育','其中:氯碱','3.黑色金属矿采选业'],'地区':['a','b','c'],'num':[23,21,34],
|
with a westernised version of your test I detected no change in rows for the following:
and a re-order of rows for:
I will guess that |
This is quite easy to fix, we are currently not passing anything to a groupby which is called unter the hood, which defaults to sort=True then. But we have a lot of tests depending on this behavior, so since this is covered not sure if we can simply change this |
I think like groupby(), it would be better to add the sort parameter, the user can decide the boolean value of sort. |
It was definitely reordered, but I didn't see the sort parameter in pivot(), so I guessed it might rely on groupby(), but after I changed the default value of sort in groupby() to False, it still didn't work. @attack68 |
The example I gave above can be corrected by going to
to
Note that changing the |
Yes but this breaks a lot of tests, hence the question what to do exactly |
If you add a sort keyword to pivot table in pivot.py#pivot_table and frame.py#pivot_table defaulting to True it doesn't impact the tests since its backwards compatible no? The the user can specify pivot_table(sort=False) directly? Or did I miss something - perhaps extension of the api is not ideal? |
cc @jreback - any thoughts on adding an argument sort=True to pivot to control the groupby used? |
Related to #15105 |
I have searched the [pandas] tag on StackOverflow for similar questions.
I have asked my usage related question on StackOverflow.
Question about pandas
Note: If you'd still like to submit a question, please read this guide detailing how to provide the necessary information for us to reproduce your question.
# Your code here, if applicable
The text was updated successfully, but these errors were encountered: