Python Forum
Multiprocessing my Loop/Iteration (Try...Except)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing my Loop/Iteration (Try...Except)
#1
Im converting one chemical notation to another type. My list has like over 6k different names to convert and it takes so long. How can I use multiprocessing? I tried to implement myself, but im a noob. Other code optimisations are welcome too!

I tried to implement multiprocessing myself, but im a noob

def resolve(str_input, representation):
    import cirpy
    return cirpy.resolve(str_input, representation)

compound_list = []
smiles_list = []

for index, row in df_Verteilung.iterrows():

    try:
        actual_smiles = resolve(row['Compound'], 'smiles')

    except:
        actual_smiles = 'Error'

    print('\r', row['Compound'], actual_smiles, end='')

    compound_list.append(row['Compound'])
    smiles_list.append(actual_smiles)

df_new = pd.DataFrame({'Compound' : compound_list, 'SmilesCode' : smiles_list})
df_new.to_csv(index=False)
Reply


Messages In This Thread
Multiprocessing my Loop/Iteration (Try...Except) - by Jompie96 - Jun-19-2019, 08:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Inconsistent loop iteration behavior JonWayn 2 1,001 Dec-10-2022, 06:49 AM
Last Post: JonWayn
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,043 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Pool multiprocessing - know current status in loop? korenron 0 1,636 Jul-28-2021, 08:49 AM
Last Post: korenron
  saving each iteration of a loop sgcgrif3 3 6,727 Jul-27-2021, 01:02 PM
Last Post: DeaD_EyE
  python multiprocessing import Pool, cpu_count: causes forever loop | help to remove Hassibayub 0 1,865 Jun-18-2020, 05:27 PM
Last Post: Hassibayub
  String slicing and loop iteration divyansh 9 4,726 Jun-07-2020, 10:29 PM
Last Post: divyansh
  Changing a variable's name on each iteration of a loop rix 6 84,715 Jan-03-2020, 07:06 AM
Last Post: perfringo
  Parallel iteration with for loop Josh_Python890 1 2,175 Jul-19-2019, 11:50 PM
Last Post: metulburr
  parallel for loop with multiprocessing dervast 0 2,015 Jul-04-2019, 03:16 PM
Last Post: dervast
  First for loop stops after first iteration Divanova94 10 8,893 May-01-2019, 04:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

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