dodger487 / dplython

dplyr for python
MIT License
763 stars 52 forks source link

Problem with mutate #95

Open Shelmith-Kariuki opened 5 years ago

Shelmith-Kariuki commented 5 years ago

screen shot 2018-11-20 at 10 38 00

I am trying to generate a variable, based on conditions of another variable, but the mutate function is failing.

dodger487 commented 5 years ago

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.

Shelmith-Kariuki commented 5 years ago

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 notifications@github.com 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 .

Shelmith-Kariuki commented 5 years ago

screen shot 2018-11-20 at 11 00 16

dodger487 commented 5 years ago

Sorry, looks like you're correct. How about this:

where = DelayFunction(np.where)
wf_df >> mutate(Jinsia = where(X.Gender == "Female", "Mke", "Mme"))
Shelmith-Kariuki commented 5 years ago

Woohoo!!! That works!!. I am opening another issue, on the spread function. screen shot 2018-11-20 at 11 38 07

Shelmith-Kariuki commented 5 years ago

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 notifications@github.com 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 .