Convert dataframe to array of tuples

The simplest way to do it is:

julia> using DataFrames

julia> df = DataFrame(x=1:4, y=2:5)
4×2 DataFrame
 Row │ x      y
     │ Int64  Int64
─────┼──────────────
   1 │     1      2
   2 │     2      3
   3 │     3      4
   4 │     4      5

julia> Tuple.(eachrow(df))
4-element Vector{Tuple{Int64, Int64}}:
 (1, 2)
 (2, 3)
 (3, 4)
 (4, 5)

If your data frame has very many rows instead do:

julia> Tuple.(Tables.namedtupleiterator(df))
4-element Vector{Tuple{Int64, Int64}}:
 (1, 2)
 (2, 3)
 (3, 4)
 (4, 5)

which is faster for very long tables.

3 Likes