-
Notifications
You must be signed in to change notification settings - Fork 375
Open
Description
Wouldn't it be great to add the Before
selector to Not
, Between
, Cols
, All
and regex column selectors?
This would simplify a bit the use case where you add a new column with transform
and move it to a specific position, for instance around the column used for the transformation.
Example:
julia> df = DataFrame(:a => [1, 2, 3, 4], :b1 => [2, 3, 4, 1], :B2 => [3, 4, 1, 2], :c => [4, 1, 2, 3])
transform!(df, [:b1, :B2] => ByRow(+) => :b)
select!(df, Cols(1:findfirst(==("b1"), names(df))-1, :b, :))
4×5 DataFrame
Row │ a b b1 B2 c
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 5 2 3 4
2 │ 2 7 3 4 1
3 │ 3 5 4 1 2
4 │ 4 3 1 2 3
julia>
The reordering would be
julia> df = DataFrame(:a => [1, 2, 3, 4], :b1 => [2, 3, 4, 1], :B2 => [3, 4, 1, 2], :c => [4, 1, 2, 3])
transform!(df, [:b1, :B2] => ByRow(+) => :b)
select!(df, Cols(Before(:b1), :b, :))
4×5 DataFrame
Row │ a b b1 B2 c
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 5 2 3 4
2 │ 2 7 3 4 1
3 │ 3 5 4 1 2
4 │ 4 3 1 2 3
After
could also be useful
julia> df = DataFrame(:a => [1, 2, 3, 4], :b1 => [2, 3, 4, 1], :B2 => [3, 4, 1, 2], :c => [4, 1, 2, 3])
transform!(df, [:b1, :B2] => ByRow(+) => :b)
select!(df, Cols(1:findfirst(==("B2"), names(df)), :b, :))
4×5 DataFrame
Row │ a b1 B2 b c
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 2 3 5 4
2 │ 2 3 4 7 1
3 │ 3 4 1 5 2
4 │ 4 1 2 3 3
Would become
julia> df = DataFrame(:a => [1, 2, 3, 4], :b1 => [2, 3, 4, 1], :B2 => [3, 4, 1, 2], :c => [4, 1, 2, 3])
transform!(df, [:b1, :B2] => ByRow(+) => :b)
select!(df, Cols(Not(After(:B2)), :b, :))
4×5 DataFrame
Row │ a b1 B2 b c
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 2 3 5 4
2 │ 2 3 4 7 1
3 │ 3 4 1 5 2
4 │ 4 1 2 3 3
Metadata
Metadata
Assignees
Labels
No labels