Python Forum
Apply a function with pandas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Apply a function with pandas (/thread-19110.html)



Apply a function with pandas - Jompie96 - Jun-13-2019

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


RE: Apply a function with pandas - stullis - Jun-13-2019

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)



RE: Apply a function with pandas - Jompie96 - Jun-13-2019

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.