How to smartly rewrite DataFrames type columns

Hi, Julian wizard people.

I want to rewrite the data in the DataFrames column.
It works fine for now, but I don’t like this writing method because it’s not smart.
The same description is repeated.
Is there a simpler, smarter way to describe it?

using DataFrames

df = DataFrame(COL01 = [1,2,3,4,5])

function helper!(args)
return args * 100
# This is sample. Actual program is more long.
end

#It works, but it’s not cool.

df[(df.:COL01 .> 2),:COL01] = helper!.(df[(df.:COL01 .> 2),:COL01])

Is there a more expert way to do this?
Please advise.

Are you coming from Stata? This is a very stat-esque way of doing things.

A few notes

  1. Your helper! function is oddly named. It doesn’t actually modify the thing it is acting on. This matters because you don’t actually need the assignment on the LHS
  2. This is definitely something DataFrames or helper packages could improve on. It’s on our radar here.

I don’t think there is a trivial solution, just intermediate variables

t = df.COL01
tsub  = t[t .> 2]
tsub .= helper.(tsub)
2 Likes

Dear pdeffebach,

Thank you very much for your kind reply.

I’m not Stata user.
I’m retired an older generation C/C++ programmer.

Please forget function name.
This is just a sample. It does not have a clear meaning.

Understood.
I look forward to seeing your new roadmap.
And I will also try to be of some help.

Thanks a lot.