We really need to standardize on a single type that reflects a single row of a 
tabular data structure that gets used both by DBI and by DataFrames.

DataFrameRow is really nice because it's a zero-copy operation for DataFrames, 
but we can't provide zero-copy semantics when pulling rows out of a database.

I tend to think we should have all tabular data systems use an OrderedDict to 
represent a single row of data.

We could then change eachrow(df) to mutate a one-time allocated OrderedDict. 
This involves non-trivial copying, but it syncs up closer with the idioms you'd 
use when working with DBI.

 -- John

On Sep 12, 2014, at 10:15 AM, Leah Hanson <astriea...@gmail.com> wrote:

> Oh, I didn't realize that. So, `eachrow(df)` is giving you 
> `[(:a,"hi"),(:x,0.703943)]` when you need `["hi",0.703943]` to use `push!`.
> 
> ~~~
> julia> df = DataFrame(a=["hi","there"],x = rand(2))
> 2x2 DataFrame
> |-------|---------|----------|
> | Row # | a       | x        |
> | 1     | "hi"    | 0.703943 |
> | 2     | "there" | 0.269876 |
> 
> julia> df2 = DataFrame(a=["oh","yeah"],x = rand(2))
> 2x2 DataFrame
> |-------|--------|----------|
> | Row # | a      | x        |
> | 1     | "oh"   | 0.138966 |
> | 2     | "yeah" | 0.856162 |
> 
> julia> for e = eachrow(df)
>          push!(df2,[v for (_,v) in e])
>        end
> 
> julia> df2
> 4x2 DataFrame
> |-------|---------|----------|
> | Row # | a       | x        |
> | 1     | "oh"    | 0.138966 |
> | 2     | "yeah"  | 0.856162 |
> | 3     | "hi"    | 0.703943 |
> | 4     | "there" | 0.269876 |
> ~~~
> 
> Does this work for you?
> 
> -- Leah
> 
> On Fri, Sep 12, 2014 at 8:54 AM, Florian Oswald <florian.osw...@gmail.com> 
> wrote:
> yeah I wasn't very clear in that example. i really need to append one row at 
> a time.
> 
> On 12 September 2014 14:50, Leah Hanson <astriea...@gmail.com> wrote:
> Have you tried append!(df2,df)?
> 
> ~~~
> julia> using DataFrames
>                                                                               
>                                                                               
>  
> julia> df = DataFrame(a=["hi","there"],x = rand(2))                           
>                                                                               
>  
> 2x2 DataFrame
> |-------|---------|----------|
> | Row # | a       | x        |
> | 1     | "hi"    | 0.862957 |
> | 2     | "there" | 0.101378 |
>                                                                               
>                                                                               
>  
> julia> df2 = DataFrame(a=["oh","yeah"],x = rand(2))                           
>                                                                               
>  
> 2x2 DataFrame
> |-------|--------|------------|
> | Row # | a      | x          |
> | 1     | "oh"   | 0.00803615 |
> | 2     | "yeah" | 0.0222873  |
>                                                                               
>                                                                               
>  
> julia> append!(df2,df)                                                        
>                                                                               
>  
> 4x2 DataFrame
> |-------|---------|------------|
> | Row # | a       | x          |
> | 1     | "oh"    | 0.00803615 |
> | 2     | "yeah"  | 0.0222873  |
> | 3     | "hi"    | 0.862957   |
> | 4     | "there" | 0.101378   |
> ~~~                                                                           
>                                                                               
>     
> 
> On Fri, Sep 12, 2014 at 7:57 AM, Florian Oswald <florian.osw...@gmail.com> 
> wrote:
> i'm trying to do this:
> 
> using DataFrames
> df = DataFrame(a=["hi","there"],x = rand(2))
> df2 = DataFrame(a=["oh","yeah"],x = rand(2))
> 
> for e in eachrow(df)
> append!(df2,e)
> end
> 
> ERROR: `append!` has no method matching append!(::DataFrame, 
> ::DataFrameRow{DataFrame}) 
> in anonymous at no file:2
> 
> or 
> 
> julia> for i in 1:nrow(df) 
> push!(df2,df[i,:]) 
> end
> 
> but that errors as well. 
> 
> this works:
> 
> julia> for i in 1:nrow(df) 
> push!(df2,array(df[i,:])) 
> end
> 
> but wondering whether that's the best way of achieving this efficiently. 
> 
> 
> 

Reply via email to