Need help: Apply-like operations with Dataframes #153
-
First of all, thank you for anyone willing to help me, and apologies for the simple question and if it's not written in the right place, but I'm having a hard time trying to figure out the answer. The thing is, imagine the following Dataframe:
What I want is to add a new column to that DF based on operations performed with one or several other columns, in a Pandas-like fashion. For example, imagine that I want to create a new column result that takes the following rule:
The idea is to obtain the following DF: In Pandas, this could be easily done by:
However, as Danfo does not support JS functions when specifying the axis in Is there a way in which I could implement this using Danfo? I have to perform several operations like this one to create several columns in my Dataframe, each column having its own rules and depending on other columns (can be one or more columns), and I wish to not have to traverse the whole df row by row with a classic for loop, ending up in not getting full advantage of Danfo |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@cgutierrezpa That's a really complicated function, and most of the parts needed to compute it properly are currently missing. The only way to implement this for now is hacky and you will have to write your own functions that can operate on dataframe values directly. This is an important function, and we'll love to add it. |
Beta Was this translation helpful? Give feedback.
-
I believe this is another example for such operations in Pandas: https://pandas.pydata.org/docs/getting_started/intro_tutorials/05_add_columns.html Would be great if support for this gets implemented. The current workaround is to build some kind of loop over rows but that gets ugly very quickly. |
Beta Was this translation helpful? Give feedback.
-
I’m case anyone comes looking. You can now use a custom JS function with apply. |
Beta Was this translation helpful? Give feedback.
I’m case anyone comes looking. You can now use a custom JS function with apply.