I am running into an error and the error message suggests that the source is JuMP. But I think the source is missing reported in dataframe. I would like to get rid of missing so the dataframe shows those entries as blanks. All the useful functions I can see would replace the whole columns whereas I would like to iterate through the whole dataframe and replace all “missing”.
The code below works fine when I create a dataframe by setting out the data within the code . This has one blank entry as I use ""
to define it.
using JuMP, Clp, DataFrames
function get_data()
Relationship = DataFrame(ID = ["A1","A2","A4"], LINK_1 = ["A5","A6","A10"],
LINK_2 = ["A3","A7",""], LINK_3 = ["A9","A11","A12"])
ID_t = collect(1:15)
ID = Vector{String}(undef,15)
for i in 1:15
ID[i]="A".*string(ID_t[i])
end
PRICE = rand(10.0:100.0,15)
Master = DataFrame(ID = ID,PRICE = PRICE)
return Relationship, Master
end
Relationship, Master = get_data()
price = Master.PRICE
model = Model(Clp.Optimizer)
@variable(model, 0<=x[Master.ID]<=1)
@variable(model,t[1:length(Relationship.ID)])
for (i, row) in enumerate(eachrow(Relationship))
for key in values(row)
if !isempty(key)
@constraint(model, t[i] == x[key])
end
end
end
Now, if I write the dataframes to CSV files and read it back in Julia, it shows the missing entries and I run into an error.
Relationship, Master = get_data()
CSV.write("Relat_2.csv",Relationship)
CSV.write("Master_2.csv",Master)
Relationship = CSV.read("Relat_2.csv")
Master = CSV.read("Master_2.csv")
price = Master.PRICE
model = Model(Clp.Optimizer)
@variable(model, 0<=x[Master.ID]<=1)
@variable(model,t[1:length(Relationship.ID)])
for (i, row) in enumerate(eachrow(Relationship))
for key in values(row)
if !isempty(key)
@constraint(model, t[i] == x[key])
end
end
end
MethodError: no method matching iterate(::Missing)
Closest candidates are:
iterate(!Matched::ExponentialBackOff) at error.jl:252
iterate(!Matched::ExponentialBackOff, !Matched::Any) at error.jl:252
iterate(!Matched::MathOptInterface.Bridges.Objective.Map, !Matched::Any...) at C:\Users\.julia\packages\MathOptInterface\ZJFKw\src\Bridges\Objective\map.jl:30
...
in top-level scope at test_example.jl:30
in isempty at base\essentials.jl:737
Initially, I got this error message on the actual problem, but I may have made some other errors
How can I replace missing with blanks (assuming that missing maybe in many columns in any rows)? I don’t want to delete whole columns or whole rows