dplython
dplython copied to clipboard
Problem with mutate

I am trying to generate a variable, based on conditions of another variable, but the mutate function is failing.
Dplython could be better at dealing with external functions (like np.where). You'd either need to make sure np.where can handle the X object, or use another piece of code. Dplython has some other built in functions for common cases like this. My guess is
mutate(Jinsia = if_else(X.Gender == "Female", "Mke", "Mme")
will do what you want.
Thanks for your reply. That also fails, with the following error, see screenshot attached.
Kind regards,
Shelmith
On Tue, Nov 20, 2018 at 10:54 AM Chris Riederer [email protected] wrote:
Dplython could be better at dealing with external functions (like np.where). You'd either need to make sure np.where can handle the X object, or use another piece of code. Dplython has some other built in functions for common cases like this. My guess is mutate(Jinsia = if_else(X.Gender == "Female", "Mke", "Mme") will do what you want.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dodger487/dplython/issues/95#issuecomment-440177111, or mute the thread https://github.com/notifications/unsubscribe-auth/AjtvmCvl0q3ghL5nsRsDTBw9N_WkxVXPks5uw7UpgaJpZM4YqivL .

Sorry, looks like you're correct. How about this:
where = DelayFunction(np.where)
wf_df >> mutate(Jinsia = where(X.Gender == "Female", "Mke", "Mme"))
Woohoo!!! That works!!. I am opening another issue, on the spread function.

Hi Chris,
Thank you so much for availing yourself today. One last issue i have encountered, Problem with Spread https://github.com/dodger487/dplython/issues/97
Kind regards,
Shelmith Kariuki
On Tue, Nov 20, 2018 at 11:10 AM Chris Riederer [email protected] wrote:
Sorry, looks like you're correct. How about this:
where = DelayFunction(np.where) wf_df >> mutate(Jinsia = where(X.Gender == "Female", "Mke", "Mme"))
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dodger487/dplython/issues/95#issuecomment-440181020, or mute the thread https://github.com/notifications/unsubscribe-auth/AjtvmIVAB4c5me73_Nb24X_-VDDqlsRyks5uw7jzgaJpZM4YqivL .