# XLSX and DataFrame column type

**URL:** <https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741>\
**Category:** General Usage\
**Tags:** dataframes, makie, xlsx, cairomakie\
**Created:** [February 25, 2024, 4:21pm UTC](https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741 "2024-02-25T16:21:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Post date:** [February 25, 2024, 4:21pm UTC](https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741/1 "2024-02-25T16:21:55Z")

</div>

Hello everyone 😁,  
I want to load an excel file with the XLSX.jl package and then convert it to DataFrame with DataFrame.jl with the following code:

`data = DataFrame(XLSX.readtable(path_data, "Sheet1"))`

However, the type of all columns is automatically set to `Any`. This is very annoying when, for example, you want to plot with Makie, which doesn’t accept `Any` types (even though the columns used are composed of a single type, such as `FLoat64`). This means you have to convert the input to the correct type every time, and give it to Makie.jl.  
How can I set the correct column type directly when loading an Excel file with XLSX.jl / DataFrame.jl?

Thanks in advance  
fdekerm

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 25, 2024, 4:34pm UTC](https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741/2 "2024-02-25T16:34:56Z")

</div>

Check [this post](https://discourse.julialang.org/t/how-to-change-field-names-and-types-of-a-dataframe/43991/15) and thread.

---

<div class="post-metadata">

**Author:** ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Post date:** [February 25, 2024, 4:39pm UTC](https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741/3 "2024-02-25T16:39:56Z")

</div>

Thanks, I indeed read the doc too quickly! You need to add the `infer_eltypes` argument to [`XLSX.readtable`](https://felipenoris.github.io/XLSX.jl/stable/api/#XLSX.readtable)

---

<div class="post-metadata">

**Author:** ![George9000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george9000/32/23619_2.png) [@George9000](https://discourse.julialang.org/u/George9000)\
**Post date:** [February 25, 2024, 6:50pm UTC](https://discourse.julialang.org/t/xlsx-and-dataframe-column-type/110741/4 "2024-02-25T18:50:10Z")

</div>

To take advantage of `CSV.read`’s eltype capabilities (such as conversion to InlineStrings) and other keyword arguments, something similar to this function may be useful:

```julia
function exceltodf(path, file, sheetname)
    inp = joinpath(path, file)
    io = IOBuffer()
    CSV.write(io, DataFrame(XLSX.readtable(inp, sheetname)))
    df = CSV.read(seekstart(io), DataFrame; normalizenames = true, dateformat = "m/d/Y", missingstring = "")
    close(io)
    return df
end

```
