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

Implement a from_records constructor #1191

Closed
grst opened this issue May 24, 2017 · 7 comments
Closed

Implement a from_records constructor #1191

grst opened this issue May 24, 2017 · 7 comments

Comments

@grst
Copy link

grst commented May 24, 2017

I am missing a way to construct a direct way to construct a DataFrame from a list of tuples, as I would do in python with pandas.DataFrame.from_records.

Input data:

records = [("A", 1), ("B", 2), ("C", 3)]`

Desired DataFrame:

│ Row │ x1  │ x2 │
├─────┼─────┼────┤
│ 1   │ "A" │ 1  │
│ 2   │ "B" │ 2  │
│ 3   │ "C" │ 3  │

I now know that I can do something like

n = length(records[1])
DataFrame([[r[i] for r in records] for i=1:n],[Symbol("x$(i)") for i=1:n])

but this feels somehow cumbersome...

@quinnj
Copy link
Member

quinnj commented May 24, 2017

I've wanted this as well.

@nalimilan
Copy link
Member

Maybe we could implement this as DataFrame(::AbstractArray{<:Tuple}) constructor? Or could that conflict with other meanings of this signature?

@ararslan
Copy link
Member

If I'm not mistaken, constructing a DataFrame from an array of arrays treats the interior arrays as columns, whereas in this proposal the tuples would be treated as rows. That's kind of weirdly inconsistent.

@grst
Copy link
Author

grst commented May 25, 2017

How about simply supporting a DataFrame(::Zip) constructor?
Then we could do DataFrame(zip(records...)) which would not feel too awkward for me.

@nalimilan
Copy link
Member

Good point. Special-casing Zip would be weird, but accepting any iterator of columns (including zip) would be a nice generalization of the existing DataTable(columns::Vector{Any}, names::Vector{Symbol}) constructor.

@nalimilan
Copy link
Member

@quinnj How does this issue stand regarding the new Tables.jl constructors?

@bkamins bkamins mentioned this issue Jan 15, 2019
31 tasks
@bkamins
Copy link
Member

bkamins commented Jul 25, 2019

We now allow it and generate column names with numbers as symbols due to Tabels.jl functionality.

@bkamins bkamins closed this as completed Jul 25, 2019
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

No branches or pull requests

5 participants