Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Argument name not found, tried df.Data and it's not working?? (Julia)

I'm working with a dataframe where the title of the column is "Data" but when I do

df.Data
ERROR: ArgumentError: column name :Data not found in the data frame
Stacktrace:
 [1] lookupname
   @ C:\Users\jerem\.julia\packages\DataFrames\S3ZFo\src\other\index.jl:250 [inlined]
 [2] getindex

@ C:\Users\jerem.julia\packages\DataFrames\S3ZFo\src\other\index.jl:259 [inlined] [3] getindex(df::DataFrame, #unused#::typeof(!), col_ind::Symbol) @ DataFrames C:\Users\jerem.julia\packages\DataFrames\S3ZFo\src\dataframe\dataframe.jl:361 [4] getproperty(df::DataFrame, col_ind::Symbol) @ DataFrames C:\Users\jerem.julia\packages\DataFrames\S3ZFo\src\abstractdataframe\abstractdataframe.jl:295 [5] top-level scope @ REPL[56]:1

But that's the entire name...

this is what I mean.

I've been having trouble with this one. Thank you!

enter image description here

like image 317
Jeremy S Avatar asked Jan 22 '26 16:01

Jeremy S


1 Answers

First I recommend you to update your DataFrames.jl installation to the latest version 1.2.2. The version you are using is over one year old. Most likely you are not using per-project configuration of packages and you are hitting a problem explained in this post.

Now - your problem is that you do not have four columns in your data, but one column, so you need to split it into four columns. You can do it like this (note that what I write here might not work on your DataFrames.jl version as it is old - but it will work after you update to DataFrames.jl 1.2.2):

julia> using DataFrames

julia> df = DataFrame("Year Data Min Max" => ["1979 3.1 3.0 3.2", "1980 4.1 4.0 4.2"])
2×1 DataFrame
 Row │ Year Data Min Max
     │ String
─────┼───────────────────
   1 │ 1979 3.1 3.0 3.2
   2 │ 1980 4.1 4.0 4.2

julia> df2 = select(df, 1 => ByRow(x -> split(x, " ")) => [:Year, :Data, :Min, :Max])
2×4 DataFrame
 Row │ Year       Data       Min        Max
     │ SubStrin…  SubStrin…  SubStrin…  SubStrin…
─────┼────────────────────────────────────────────
   1 │ 1979       3.1        3.0        3.2
   2 │ 1980       4.1        4.0        4.2

julia> df3 = select(df2,
                    1 => ByRow(x -> parse(Int, x)),
                    2:4 .=> ByRow(x -> parse(Float64, x)),
                    renamecols=false)
2×4 DataFrame
 Row │ Year   Data     Min      Max
     │ Int64  Float64  Float64  Float64
─────┼──────────────────────────────────
   1 │  1979      3.1      3.0      3.2
   2 │  1980      4.1      4.0      4.2

julia> df3.Data
2-element Vector{Float64}:
 3.1
 4.1

I have performed the transformation in two steps to make it easier to follow

like image 199
Bogumił Kamiński Avatar answered Jan 24 '26 07:01

Bogumił Kamiński