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

Pandas.DataFrame doesn't preserve the column order when converting from a DataFrames.DataFrame #72

Closed
dimili opened this issue Jun 11, 2020 · 1 comment · Fixed by #73

Comments

@dimili
Copy link

dimili commented Jun 11, 2020

When converting from a DataFrames.DataFrame, the order of the columns is not preserved. Instead, the columns are sorted in alphabetical order. Is this intentional?

using DataFrames
import Pandas

df = DataFrame(C = 1:4, A = 5:8, B = 9:12)
pdf = Pandas.DataFrame(df)
print(df)
4×3 DataFrame
│ Row │ C     │ A     │ B     │
│     │ Int64 │ Int64 │ Int64 │
├─────┼───────┼───────┼───────┤
│ 1   │ 1     │ 5     │ 9     │
│ 2   │ 2     │ 6     │ 10    │
│ 3   │ 3     │ 7     │ 11    │
│ 4   │ 4     │ 8     │ 12    │
print(pdf)
   A   B  C
0  5   9  1
1  6  10  2
2  7  11  3
3  8  12  4
@PallHaraldsson
Copy link
Contributor

PallHaraldsson commented Sep 24, 2020

It's probably not intentional, and isn't even always in alphabetical order. It's because Dicts in Julia do not guarantee any order (OrderedDicts do, and possibly a better way to do that, as it's not in the standard library):

cols = Dict{Symbol,Any}(i[1]=>i[2] for i in zip(column_names, columns))

When converting (Name was first column) I got:

julia> pdf
    Age  Income  Children   Name
0  34.0  120000         2   John

PandasLite.jl gave me the same order:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants