Python Forum
Apply a function with pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apply a function with pandas
#1
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
Reply
#2
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)
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to apply function lower() to the list? Toltimtixma 2 776 Feb-10-2023, 05:15 PM
Last Post: Toltimtixma
  Use of groupby in a function with Pandas Paulman 0 945 Dec-03-2021, 04:56 PM
Last Post: Paulman
  IF statement to apply at each date illmattic 2 2,634 Apr-08-2021, 12:31 PM
Last Post: illmattic
  Function won't apply dynamically in timeseries illmattic 1 1,725 Jan-08-2021, 03:15 PM
Last Post: stullis
  Pandas's regular expression function result is so strange cools0607 6 3,150 Jun-15-2020, 07:34 AM
Last Post: cools0607
  How to apply VLookup formula jonzee 2 3,527 Jan-12-2020, 04:16 PM
Last Post: Clunk_Head
  Issue in .apply function fullstop 0 1,491 Dec-17-2019, 01:29 PM
Last Post: fullstop
  Converting Smiles to Fingerprint with pandas iterrows/apply-function: Jompie96 0 2,483 Jul-04-2019, 01:50 PM
Last Post: Jompie96

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020