I would like to read a CSV-file and then convert it to a list of dicts, where the keys can contain arrays.
But with the following code I get the error message
ERROR: MethodError: Cannot convert an object of type Array{Int64,1} to an object of type DataType
Can somebody explain me what I´m doing wrong?
using DataFrames
using CSV
df_train_plan_raw =CSV.read(<file>)
dict_train_plan = [Dict(name => Any for name in names(df_train_plan_raw) if name != :no_models)
for i in 1:Int32(sum(df_train_plan_raw.no_models))]
dict_train_plan = [Dict(name => Any for name in names(df_train_plan_raw) if name != :no_models)
for i in 1:Int32(sum(df_train_plan_raw.no_models))]
dict_train_plan[1][:layer_neurons] = [parse(Int64, elem) for elem in split(df_train_plan_raw.layer_neurons[1], ">")]
This is a good case for trying to come up with an MWE - effectively your issue can be reduced down to
d = Dict("key1" => Any)
d["key1"] = 5
When you create dict_train_plan your call to the constructor is Dict(name => Any) which creates a dictionary that expects its values to be of type DataType.
I’m not exactly sure what you’re trying to achieve here and what do you need your final dictionaries to look like, can’t really recommend a solution.
I did type out a little bit of example data for others to reproduce the error though:
My goal is to get a dictionary, where I can iterate over to train several different models with keras. Therefore I would like to convert the dataframe to a dictionary, where the parameters are similiar to the arguments of the function call of keras.
Or more directly using my example data from above:
df_train_plan_raw[!, :layer_neurons_int] = [[parse(Int, i) for i in j] for j in split.(df_train_plan_raw.layer_neurons, ">")]
df_train_plan_raw.layer_neurons_int[1] # returns [30, 30]