-
Notifications
You must be signed in to change notification settings - Fork 370
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
Provide convertion from dictionary to DataFrames #591
Comments
Those methods would go in od = OrderedDict()
od[:a] = [1, 2]
od[:b] = [2, 3]
# The Associative method is broken -- I'll try to fix it soon
DataFrame(od)
ERROR: no method getindex(KeyIterator{HashDict{Any,Any,Int64}}, Int64)
in DataFrame at /Users/sean/.julia/v0.3/DataFrames/src/dataframe/dataframe.jl:94
# In the meantime, the method for Dicts works
DataFrame(Dict(od))
2x2 DataFrame
|-------|---|---|
| Row # | a | b |
| 1 | 1 | 2 |
| 2 | 2 | 3 |
# But it won't work for your example because column names are expected to be
# symbols or convertible to symbols You could hook up something like this in your own code: df = DataFrame()
for (k, v) in od
df[DataFrames.identifier(string(k))] = v
end But I'm guessing you'll want to go elsewhere for printing Dicts with numeric keys -- DataFrame colnames are required to be valid Julia identifiers, so |
I think that I didn't make point of using dictionaries instead of |
Thanks @rominf -- you can definitely use the code snippet at the bottom of my last post, though you may not be happy with the way it mangles the "indices" (keys). The packaged |
OK, I agree. |
|
Sometimes it's convenient to work with Arrays that starts from the zero (or from any other index).
I can use
OrderedDict
to achieve Array-like structures. The problem is that printing dictionaries is still ugly (JuliaLang/julia#1759). ButDataFrames
give me better printing. I want to be able to convertDict
(orOrderedDict
) to theDataFrames
in one command.This code works fine for me but I don't know whether is good or not and where should I put it (in the DataFrames or in the DataStructures code?)
or (I saw somewhere that
DataFrame
constructor without column names is deprecated):Example of usage:
Output:
UPD: I want to use
Dict
instead ofArray
because I want to be able to do those kind of stuff:or
The text was updated successfully, but these errors were encountered: