Giter VIP home page Giter VIP logo

Comments (3)

grst avatar grst commented on July 28, 2024

I believe this is part of a larger problem: any kind of standard python functions that have not specifically been adapted for dfply do not work. Take for example joining multiple str columns together:

df >> mutate(new_col = "_".join([col1, col2, col3]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-4cac91689aba> in <module>
----> 1 ap_raw >> mutate(cell_name = "_".join([X.patient, X.cellid]))

TypeError: sequence item 0: expected str instance, Intention found

from dfply.

jwdink avatar jwdink commented on July 28, 2024

I think the problem is just that in python the order of operations is different. If you wrapped your conditions with parentheses I believe it would work.

E.g. this works:

from dfply import *

@make_symbolic
def np_where(bools, val_if_true, val_if_false):
    return np.where(bools, val_if_true, val_if_false)

df = pd.DataFrame({'cond1' : [0,1], 'cond2' : [1,0]})
df >> mutate(result = np_where((X.cond1 == 1) & (X.cond2 == 1), 5, 2))

from dfply.

jwdink avatar jwdink commented on July 28, 2024

Also note that the package seems to have an if_else function built in. See https://github.com/kieferk/dfply/blob/master/dfply/vector.py. Although it seems to use a list-comprehension instead of np.where, so could potentially be slower than needed.

from dfply.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.