The variable "data" which you've formed, will be computed for every row even though columns won't change. You should move it up and pass it to gen directly. This will save repeated computations.
Secondly, it should not be named as data. It can be like - numeric_cols or numeric_keys.