Le jeudi 24 mars 2016 à 09:35 -0700, Fred a écrit :
> Hi,
>
> I have a DataFrame "df" and I would like to create a new DataFrame
> "m" with the same colnames than df.
> And then, append to "m" the rows of "df" matching a complex set of
> conditions, so I need to test many conditions for each row.
>
> The problem I have is to create an empty dataframe "m" with the sames
> colnames of "df" and then to append the rows matching conditions to
> it.
>
> df = readtable("file.tsv")
>
> # trying to create an empty copy of df
> m = DataFrame()
> names!(m, names(df)) # produce error ArgumentError: Length of nms
> doesn't match length of x
> # but I did not manage to create m with the same cols number than df.
>
>
> z = size(df)[1]
>
> # for each row of df append the rows matching many conditions on many
> columns
> for i = 1:z
> if condition(df[:colname_x][i])
> push!(m,i)
> end
> end
>
> Thank you for your comments !
You can use similar() for this:
m = similar(df, 0)
Regards