I'm trying to make a function that converts dataframe to vector of tuples in Julia.
For example,
using DataFrames
df = DataFrame(A=1:4, B=4:7, C=10:13)
4×3 DataFrame
Row │ A B C
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 1 4 10
2 │ 2 5 11
3 │ 3 6 12
4 │ 4 7 13
T = [t for t in zip(df.A, df.B, df.C)]
T = 4-element Vector{Tuple{Int64, Int64, Int64}}:
(1, 4, 10)
(2, 5, 11)
(3, 6, 12)
(4, 7, 13)
Then T becomes the result what I exactly wanted.
The problem is, however, that I need to functionalize above process.
So, what I need is to automatically put columns of dataframe into the zip function.
The form of function that I want to make is as below
using DataFrames
function DataframeToTuple(df)
T = [t for t in zip(df.first column name, df.second column name, ... df.last column name)]
return T
end
Is there any convenient way? Thanks a lot