Skip to content

Add convenience function to look up a single value in a DataFrame #394

Description

@nathanrboyer

It would work similarly to @rsubset but it would automatically call only and extract the desired value.

For example:

julia> df = DataFrame(x = 1:5, y = ["A","A","B","B","B"], z = (1:5)./10)
5×3 DataFrame
 Row │ x      y       z
     │ Int64  String  Float64
─────┼────────────────────────
   11  A           0.1
   22  A           0.2
   33  B           0.3
   44  B           0.4
   55  B           0.5

julia> zvalue = @rsubset(df, :x > 1, :y == "A").z |> only
0.2

julia> zvalue = @lookup(df, :z, :x > 1, :y == "A")
0.2

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 match rsubset, 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions