-
Notifications
You must be signed in to change notification settings - Fork 55
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
Add convenience function to look up a single value in a DataFrame
#394
Comments
Since this is a meta package, it may not need to look like a function call at all. The syntax could be something more exotic? zvalue = df[@lookup, :z] :x > 1, :y == "A" |
That particular syntax isn't actually possible, since Moreover, I would definitely want to avoid that kind of exotic syntax. DataFrames.jl doesn't have any |
Any chance of you looking into implementing this in the near future? I started looking at it myself this morning, but I have not made much progress ... ##############################################################################
##
## @lookup - select unique rows and values
##
##############################################################################
function lookup_helper(x, args...)
@rsubset(x, args...) |> only
end
macro lookup(x, args...)
esc(lookup_helper(x, args...))
end
macro lookup(x, y::Union{Symbol,AbstractString}, args...)
@lookup(x, args...)[:, y] |> only
end julia> using DataFramesMeta
Precompiling DataFramesMeta...
Info Given DataFramesMeta was explicitly requested, output will be shown live
ERROR: LoadError: syntax: "..." expression outside call I would need to learn a lot about macros to get something functional. |
It would work similarly to
@rsubset
but it would automatically callonly
and extract the desired value.For example:
It could maybe also work without the second argument to return a
DataFrameRow
.It was mentioned that this may need to be called
rlookup
to matchrsubset
, but I think that is not necessary if the single value method is implemented. (This discussion started in the DataFrames.jl repository: JuliaData/DataFrames.jl#3051 (comment))Would this function make DataFrames lookups more accessible to newcomers, or is the existing
@rsubset
functionality good enough?The text was updated successfully, but these errors were encountered: