Reputation: 31
I am trying to convert dataframe columns from string to int to boolean using a loop. I have confirmed that n does correctly catch the df column names but am unable to reference them in the convert statement.
for n in (names(df))
df[!,:n] = convert.(Bool, (parse.(Int,df[!,:n])))
end
The error I get is:
ERROR: LoadError: ArgumentError: column name :n not found in the data frame
Upvotes: 2
Views: 569
Reputation: 153
You shouldn't use :
before the column names, and parse
can parse a string as a Bool too.
transform!(df, names(df) .=> ByRow(x->parse(Bool, x)), renamecols = false)
Upvotes: 2