Julia: How to obtain the types of every column of a DataFrame/Table?

There must be an easy way to obtain the column types of every column of a DataFrame. Currently, I do

using DataFrames
a = DataFrame(a = [1,2,3], str = ["a","b","c"], f = [0.0, 1.0, 5.0])
[eltype(Array(col)) for col in eachcol(a)]

Is the best way? Appreciate more efficient and elegant solutions

1 answer

  • answered 2019-09-10 03:12 Cameron Bieganek

    Use eltypes from the DataFrames package:

    julia> df = DataFrame(a = [1,2,3], str = ["a","b","c"], f = [0.0, 1.0, 5.0]);
    julia> eltypes(df)
    3-element Array{DataType,1}:

    EDIT: According to @BogumilKaminski, eltypes will soon be deprecated. After it is deprecated, the most concise approach will be to use eltype.(eachcol(df)).