How to sum columns that match column selector #10675
-
For example, if I have a list of columns in my table The expected syntax is something ilke: summed_output = penguins.mutate(
numeric_sum=sum(s.numeric())
) or possibly: summed_output = penguins.mutate(
numeric_sum=s.apply(s.numeric(), sum)
)
# apply takes a column selector and general function I was able to work out a solution that's a bit syntactically long: summed_output = penguins.mutate(
numeric_sum=sum(
[
penguins[col] for col in penguins.select(s.numeric()).columns
]
)
) is there a cleaner alternative that I'm missing? thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
or perhaps there's just a way to get the names of a table's columns without doing this: |
Beta Was this translation helpful? Give feedback.
Hey @tkbadamdorj! We've talked about how to make these "sum across" operations cleaner but haven't spent the time to really dig in. Your solution is the correct one with the current API. I have a version that uses
map
and alambda
but I think it's a bit more awkward.