Python Forum

Full Version: Apply a function with pandas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey I'm doing research now and I have problems to apply a function to my data.
Here is the function I want to apply:

import cirpy
cirpy.resolve ("taurine", "smiles")

taurine is the value I want to translate into smiles-form (type of chemical notation)

Here Is my code:

df2["Compound"] = df2["Compound"].apply(lambda x: cirpy.resolve x, "smiles")

"Compound" is the column I want to apply the function.

It doesn't work tho

PLS HELP I'm DYING
To simplify this, wrap the cirpy.resolve() function in another function:

# Creates a function with only one argument
# and dummies out the second argument to cirpy.resolve
def resolve(x):
    return cirpy.resolve(x, "smiles")
With that in place, you can do this:


df2["Compound"] = df2["Compound"].apply(resolve)
Hey Stullis, thanks for your answer.
I tried your way but I got the error: quote_from_bytes() expected bytes

Sorry I'm a noob. I don't know how to solve that problem.