Maybe you had a mistake at fieldnames. It require the struct inself, not instance. Use typeof function to get the name of class(structure).
julia> struct MyStruct
x::Vector{Float64}
y::Vector{Float64}
end
julia> function struct_to_dataframe(s)
fields = fieldnames(typeof(s))
still_vector = [getfield(s,field) for field in fields]
return DataFrame(hcat(still_vector...), collect(fields))
end
struct_to_dataframe (generic function with 1 method)
julia> s = MyStruct(rand(10),rand(10));
julia> struct_to_dataframe(s)
10×2 DataFrame
Row │ x y
│ Float64 Float64
─────┼──────────────────────
1 │ 0.286858 0.140575
2 │ 0.253701 0.821031
3 │ 0.767813 0.474758
4 │ 0.669886 0.74336
5 │ 0.463448 0.956407
6 │ 0.692433 0.715941
7 │ 0.520875 0.447658
8 │ 0.783861 0.00811924
9 │ 0.928598 0.885618
10 │ 0.681593 0.271318