How to replace/set/change value in array/dataframe if value is less/greater than?

Hello, I had some code that used to work but it must have been for a previous version of Julia. I can’t find what I am looking for in the DataFrame docs https://dataframes.juliadata.org/stable/man/getting_started/#Replacing-Data

I want to replace values in an array or DataFrame that are less than 0.5 to 0.0.

QWER = rand(5, 5)
QWER[QWER .>= 0.5] .= 0.0

This gives a 12 element view, everything is set to 0.0.

QWER = [QWER .<= 0.5] .= 0.0

This gives the error
MethodError: Cannotconvert an object of type Float64 to an object of type BitArray{2}

using DataFrames
QWER = DataFrame(QWER)
QWER = [QWER .<= 0.5] .= 0.0

This gives the error
MethodError: Cannot convert an object of type Float64 to an object of type BitArray{2}

QWER[QWER .>= 0.5] .= 0.0 

This gives the error
MethodError: no method matching getindex(::DataFrame, ::DataFrame)

What is the correct way to do this?
#########
Answer edit:

For a DataFrame

For Arrays the first solution is correct. Just look at QWER.
For DataFrames something like

df[df.col1 .> 0.5,:col1] .= 0.0

should do the trick

Thank you for your reply - you are correct, the arrays solution works.

Does the DataFrames on not just specify the first column (assuming it is named col1)?

Yes, if you want to change all of the columns, then use

QWER .= ifelse.(QWER .> 0.5, 0.0, QWER)
2 Likes