julia> using DataFrames
julia> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ String │
├─────┼───────┼────────┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
│ 3 │ 3 │ F │
│ 4 │ 4 │ M │
julia> df1 = df[1, :]
1×2 DataFrame
│ Row │ A │ B │
│ │ Int64 │ String │
├─────┼───────┼────────┤
│ 1 │ 1 │ M │
julia> df1.A
1-element Array{Int64,1}:
1
julia> df1[:A]
1-element Array{Int64,1}:
1
Is there a way to define a df1 (for a row) so that both/either df1.A and/or df1[:A] get me the Int64 element rather than a 1-element Array{Int64,1}? I hope to do away with the syntax of df1.A[1] or df1[:A][1].
DataFramesMeta.jl has a number of great convenience features for DataFrames. Depending on what you want to do with the row information, @byrow might fit your use case:
let x = 0.0
@byrow! df begin
if :A < :B
x += :B * :C
end
end
x
end
Apologies, even the first one was incorrect! I simply got a Dict with the column index, so the 1 returned wasn’t the 1 in df[1, :A] but simply the index of column :A which happens to be 1 as well! Discard my answer!