Skip to content
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

GroupBy then combine changes column order #3404

Open
Tambup opened this issue Nov 17, 2023 · 2 comments
Open

GroupBy then combine changes column order #3404

Tambup opened this issue Nov 17, 2023 · 2 comments
Labels
Milestone

Comments

@Tambup
Copy link

Tambup commented Nov 17, 2023

Hi all,

I just noticed that when groupby and then combine are used, the order of columns changes. I think it is a reasonable behavior, but I think it would be good to point out with a "warning" in the doc. This can lead to unexpected behavior in some cases.

Julia version: 1.9.3
DataFrames version: 1.5.0

Example:

df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
df = combine(first, groupby(df, :B))
for (Bval, Aval) in eachrow(df) # I expect here (Aval, Bval) without seeing any warning in the doc
    println("Col B value is:", Bval, "\tCol A value is:", Aval)
end
@bkamins bkamins added this to the 1.7 milestone Nov 17, 2023
@bkamins bkamins added the doc label Nov 17, 2023
@bkamins
Copy link
Member

bkamins commented Nov 17, 2023

Technically the order of columns is not changed (the point is that the columns not specified for grouping are dropped). However, indeed we could add a sentence that if keepkeys=true then in combine grouping columns are put first and are followed by results of the aggregation as I think it is missing.

@Tambup
Copy link
Author

Tambup commented Nov 18, 2023

Yes, I think it is a great idea.

@bkamins bkamins modified the milestones: 1.7, 1.x Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants