Is there a way to access current_row_index in the following snippet ?
@with df begin
fn.(:col, current_row_index)
end
Is there a way to access current_row_index in the following snippet ?
@with df begin
fn.(:col, current_row_index)
end
No, unfortunately that is not possible. You would have to create a column storing the row number to do this.
@eachrow
and @eachrow!
allow the use of the row index, but they have different behavior than @with
.
There’s a solution julia - Is it possible to access row index inside DataFramesMeta macros? - Stack Overflow
julia> using DataFramesMeta
julia> fn(x, y) = (x, y)
fn (generic function with 1 method)
julia> df = DataFrame(col=["a", "b", "c"])
3×1 DataFrame
Row │ col
│ String
─────┼────────
1 │ a
2 │ b
3 │ c
julia> @with df begin
fn.(:col, axes(df, 1))
end
3-element Vector{Tuple{String, Int64}}:
("a", 1)
("b", 2)
("c", 3)