1

I have a DataFrame df with a column named "cond". One of the values in this column is "aer". To select all the rows with cond == "aer", this code works:

select(:(cond .== "aer"), df)

But this doesn't

select(:(contains(["aer"],cond)), df)

It fails with the error:

ERROR: all SubDataFrame indices must be > 0 in SubDataFrame at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1007 in sub at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1020 in select at /Users/seanmackesey/.julia/DataFrames/src/dataframe.jl:1031

I looked at the source but fail to understand what's going on here. What are the general limitations on what I can put in expression predicates like this?

1 Answer 1

1

I think the problem is that contain isn't a vectorized operation:

julia> contains(["aer"], ["aer", "aer", "abr"])
false

This probably means that it's not generating valid indices.

In general, the family of expressions that should work in select are those that generate a vector of indices. There are a few broken cases, but I believe the problem in this case is just that the predicate isn't producing useful indices.

2
  • I think there is an error contain -> contains. Apparently I can not edit your answer because the fix is less than 6 characters.
    – ivarne
    Oct 11, 2013 at 13:48
  • @JohnMylesWhite I see-- is there a simple way to take any expression that would return true/false for each row and wrap it so that it can return a vector of indices? I tried doing @vectorize_2arg Any contains but this did not work. Oct 11, 2013 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.