Jump to content

Run python data function on multiple columns

Sean Flaherty 2

Recommended Posts


I have a need to run a calculation using a python library on 1-to-n columns depending on the data set andoutputting the result to a column

I couldcreate a data function with the necessary calculation and manually reuse itmappingthe input parameter to point to adifferent columnbut it would still have the same output column name. Alternatively, I could create multiple data functions with the same calculation and different output parameters but that is a lot of redundant work.

Is there a better way to do data function calculations in a single script with 1-to-n input columns andassociated to 1-to-n output columns


Thank you and kind regards,


Link to comment
Share on other sites

I'm doing similar stuff with R using dplyr. I'm starting with an empty list. Then each iteration over i will save a resulting data frame at position i of the list. (You can also include another function to change the column header before saving it to the list.) When the loop is finished I bind all results together using 'bind_cols' function. And finally I bind the results to the original data frame.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...