# How to convert all columns of type Int8 to Int64

**URL:** <https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [March 3, 2021, 3:19pm UTC](https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413 "2021-03-03T15:19:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kobusherbst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kobusherbst/32/19682_2.png) [@kobusherbst](https://discourse.julialang.org/u/kobusherbst)\
**Post date:** [March 3, 2021, 3:19pm UTC](https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413/1 "2021-03-03T15:19:55Z")

</div>

I have a dataframe with quite a few columns of type Int8 that I need to convert to Int64 to satisfy XLSX.jl non-support for integer sizes other than Int64.

Currently I do it column by column:  
` sf[!,:Enumeration] = convert.(Int64, sf[:, :Enumeration]) #needed by XLSX`

There must be a better way, but I am too much of a novice to figure it out.

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [March 3, 2021, 3:30pm UTC](https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413/2 "2021-03-03T15:30:14Z")

</div>

You can find the names of the columns that are `Int8` using `names(df, Int8)`.

```julia
ulia> using DataFrames

julia> df = DataFrame(a = rand(1:10, 5), b = randn(5), c = Int8.(rand(11:20, 5)))
5×3 DataFrame
 Row │ a b c    
     │ Int64 Float64 Int8 
─────┼─────────────────────────
   1 │ 10 0.0594745 17
   2 │ 5 -2.09879 12
   3 │ 10 -0.765042 17
   4 │ 6 -0.258906 12
   5 │ 7 -0.721766 18

julia> names(df, Int8)
1-element Vector{String}:
 "c"

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 3, 2021, 3:32pm UTC](https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413/3 "2021-03-03T15:32:48Z")

</div>

First of all, welcome to our community! 🎊

Complementing the suggestion of @dmbates, use `names` and then iterate over it:

```julia
for int8_col_name in names(sf, Int8)
    sf[!, int8_col_name] = convert.(Int64, sf[:, int8_col_name])
end

```

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 3, 2021, 3:43pm UTC](https://discourse.julialang.org/t/how-to-convert-all-columns-of-type-int8-to-int64/56413/4 "2021-03-03T15:43:39Z")

</div>

This is even more concise:

```julia
transform!(sf, names(sf, Int8) .=> ByRow(Int), renamecols=false)

```
