Replace strings in pandas dataframe / Memo

I would like to convert smiles string which has Cl or Br atoms convert to new one which has L as Cl and R as Br.
I wrote simple code for my note.

import pandas as pd
df = pd.read_table('cdk2.smi', sep=' ')
# make replace function with lumbda function
rep_func = lambda x: x.replace('Cl', 'L').replace('Br','R')
df['repsmi'] = df.SMILES.apply(rep_func)
for row in df.repsmi:                                      
    ...:     if "L" in row:
    ...:         print(row)
    ...:     else: pass

Result was..


OK. If I use vectrize function the performance will be increased.


Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: