I have a DataFrame with Int64 columns:
using DataFrames
df = DataFrame(a=1:3,b=4:6,c=["a","b","c"])
3×2 DataFrame
Row │ a b c
│ Int64 Int64 String
─────┼──────────────────────
1 │ 1 4 a
2 │ 2 5 b
3 │ 3 6 c
Now, I want to change the column types to Float64. I know that I can do something like...
using DataFramesMeta, Chain
@chain df begin
@transform!(:a = Float64.(:a),
:b = Float64.(:b))
end
or
df.a = Float64.(df.a)
df.b = Float64.(df.b)
But how can I change all columns of type Int64 to Float64. Columns of other types should stay as they are.
(As you might guess from the example above I like the combination of Chain and DataFramesMeta, but of course all answers are more than welcome.)
The simplest way to do it is (this updates your original data frame):
With
transform!you can alternatively do:or you can also do:
(sorry - no DataFramesMeta.jl here yet - but things might change in the future)
If you want to change only e.g. columns that have
Inttype then do:or