Relate[!, 1] = map(convert(Int64, Relate[!, 1]))
Especially convert(Int64, Relate[!, 1])
is exactly what the error says, that tries to convert the whole column into a number.
Did you want to change the eltype to Int
?
Also, what are all the map
s supposed to do? What is the structure of Relate? Maybe we can work from this forwards.
Suppose you have:
julia> df = DataFrame((as = Any[1:10...], bs = rand(10), names = Any["Col_$(i)" for i in 1:10]))
10×3 DataFrame
Row │ as bs names
│ Any Float64 Any
─────┼────────────────────────
1 │ 1 0.452431 Col_1
2 │ 2 0.965297 Col_2
3 │ 3 0.0673582 Col_3
4 │ 4 0.319082 Col_4
5 │ 5 0.53456 Col_5
6 │ 6 0.175433 Col_6
7 │ 7 0.131868 Col_7
8 │ 8 0.996933 Col_8
9 │ 9 0.275728 Col_9
10 │ 10 0.326396 Col_10
What about:
julia> df.as = convert.(Int, df.as);
julia> df.names = string.(df.names);
julia> df
10×3 DataFrame
Row │ as bs names
│ Int64 Float64 String
─────┼──────────────────────────
1 │ 1 0.452431 Col_1
2 │ 2 0.965297 Col_2
3 │ 3 0.0673582 Col_3
4 │ 4 0.319082 Col_4
5 │ 5 0.53456 Col_5
6 │ 6 0.175433 Col_6
7 │ 7 0.131868 Col_7
8 │ 8 0.996933 Col_8
9 │ 9 0.275728 Col_9
10 │ 10 0.326396 Col_10
Florian Große said:
Suppose you have:
julia> df = DataFrame((as = Any[1:10...], bs = rand(10), names = Any["Col_$(i)" for i in 1:10])) 10×3 DataFrame Row │ as bs names │ Any Float64 Any ─────┼──────────────────────── 1 │ 1 0.452431 Col_1 2 │ 2 0.965297 Col_2 3 │ 3 0.0673582 Col_3 4 │ 4 0.319082 Col_4 5 │ 5 0.53456 Col_5 6 │ 6 0.175433 Col_6 7 │ 7 0.131868 Col_7 8 │ 8 0.996933 Col_8 9 │ 9 0.275728 Col_9 10 │ 10 0.326396 Col_10
What about:
julia> df.as = convert.(Int, df.as); julia> df.names = string.(df.names); julia> df 10×3 DataFrame Row │ as bs names │ Int64 Float64 String ─────┼────────────────────────── 1 │ 1 0.452431 Col_1 2 │ 2 0.965297 Col_2 3 │ 3 0.0673582 Col_3 4 │ 4 0.319082 Col_4 5 │ 5 0.53456 Col_5 6 │ 6 0.175433 Col_6 7 │ 7 0.131868 Col_7 8 │ 8 0.996933 Col_8 9 │ 9 0.275728 Col_9 10 │ 10 0.326396 Col_10
@Florian Große , was able to implement:
begin
Relate[!, 1:3] = convert.(Int, Relate[!, 1:3])
Relate[!, 4:6] = float.(Relate[!,4:6])
Relate[!, 7:9] = string.(Relate[!, 7:9])
first(Relate, 5)
end
When I hover over the dataframe in the output,
the float fields do not show the data type.
Any suggestion?
I don't really understand what you mean by "hover over". Is this code in a Pluto notebook?
Florian Große said:
I don't really understand what you mean by "hover over". Is this code in a Pluto notebook?
@Florian Große , yes it is. v1.5.3
what does typeof.(df[!,name] for name in names(df))
yield for you after conversion?
Florian Große said:
what does
typeof.(df[!,name] for name in names(df))
yield for you after conversion?
@Florian Große , the following is returned
DataType
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
Array{Union{Missing, Float64},1}
too bad, can't make it visible myself
thanks, so the types appear to be correct. Does it matter whether you see them or not?
If it does, it's probably something for the #pluto.jl channel
(assuming the problem is related to Pluto, I still don't exactly understand what you mean by hover over)
Florian Große said:
If it does, it's probably something for the #pluto.jl channel
@Florian Große -- Thank you I will reach out to them about it.
What I mean is, once you generate an output, in this case
a dataframe, you can move your mouse over the column
headings and see the eltype for each field.
I see, that's nice, I never tried that
Have you tried using infer_eltypes=true
so that XLSX.jl just infers the types for you?
Nils said:
Have you tried using
infer_eltypes=true
so that XLSX.jl just infers the types for you?
Excellent -- thank you @Nils , this worked.
I used
DeadAvenger = DataFrame(xl.readtable("Data.xlsx", "IronMan",
infer_eltypes=true)...)
Might you know of a website that lists the parameters for
common methods? I posted the question to the general
board previously.
Thank you,
The answer that was given to you in the other thread stands: most packages have documentation, and while that is not always complete, it is pretty good for the packages you're deling with (DataFrames, CSV, XLSX). Here it is for XLSX.readtable
: https://felipenoris.github.io/XLSX.jl/dev/api/#XLSX.readtable
Last updated: Dec 28 2024 at 04:38 UTC