Hi all
julia noob here. I’m trying to get to grips with changing some functionality in my code based on some excellent guidance from wonderful members of discourse. I have the code “working” but one approach SHOULD work and the other DOES work. I want to know what I am missing. Here is the situation.
thank you for any help.
I have the following dataframe ( from a csv)
Type Symbol
STK XLU
STK XLV
STK XOP
STK XRT
CASH EUR
CASH GBP
CASH AUD
CASH JPY
CASH CHF
CASH CAD
IND VIX
IND RVX
IND VXN
IND VXD
FUT ES
FUT CL
I want just the STK rows so I filter
symbol_list = symbol_data[symbol_data.Type .== "STK", :]
and get
Type Symbol
STK XLU
STK XLV
STK XOP
STK XRT
so far so good. NOW comes the tricky bit
I want to build a Dataframe like this
Symbols price ticksize
XLU 0.0 0.0
XLV 0.0 0.0
XOP 0.0 0.0
XRT 0.0 0.0
someone was kind enough to send me this code
df = DataFrame(symbols = symbol_list, price = zeros(length(symbol_list)), tickSize = zeros(length(symbol_list)))
which gives me this error
RROR: MethodError: no method matching length(::DataFrame)
Closest candidates are:
length(::Union{Base.KeySet, Base.ValueIterator}) at ~/julia-1.7.0/share/julia/base/abstractdict.jl:58
length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at ~/julia-1.7.0/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:171
length(::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at ~/.julia/packages/DataStructures/vSp4s/src/ordered_robin_dict.jl:86
...
as does
df = DataFrame(symbols = symbol_list.Symbol, price = zeros(length(symbol_list)), tickSize = zeros(length(symbol_list)))
ERROR: MethodError: no method matching length(::DataFrame)
Closest candidates are:
length(::Union{Base.KeySet, Base.ValueIterator}) at ~/julia-1.7.0/share/julia/base/abstractdict.jl:58
length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at ~/julia-1.7.0/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:171
length(::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at ~/.julia/packages/DataStructures/vSp4s/src/ordered_robin_dict.jl:86
...
YET
symbol_list2 = symbol_list.Symbol
df = DataFrame(symbols = symbol_list2, price = zeros(length(symbol_list2)), tickSize = zeros(length(symbol_list2)))
works fine???
symbols price ticksize
XLU 0.0 0.0
XLV 0.0 0.0
XOP 0.0 0.0
XRT 0.0 0.0
what’s the difference between
typeof(symbol_list2)
Vector{Union{Missing, String7}} (alias for Array{Union{Missing, String7}, 1})
and
typeof(symbol_list.Symbol)
Vector{Union{Missing, String7}} (alias for Array{Union{Missing, String7}, 1})