Skip to content

feature: cols=:union argument (or something like it) for combine with AsTable #3005

@kleinschmidt

Description

@kleinschmidt

I have a function myfun that operates on one or more rows from my dataframe, and returns a Tables compliant output. The columns will not always be the same for every input. I'd like to be able to do something like

combine(groupby(df, :group1, :group2), [:input1, :input2] => my_fun => AsTable)

But I get an error that the keys must all be the same, and there's no cols argument to control how that is handled.

If I want to do this manually, I can do something like (thanks to @bkamins for suggesting):

reduce(vcat, [insertcols!(DataFrame(myfun(v.input1, v.input2)), k...) for (k, v) in pairs(groupby(df, :group1, :group2)] ; cols=:union)

but that's pretty clunky and you miss out on the nice transform syntax (have to manually do v.input1 etc.).

I propose adding a cols kwarg to combine to control how keys are handled from AsTable, although that my be a bit punny.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions