Python Pandas iterrows and set_value as vectorized function -


i using function in 1 of programs, , have researched better performance can achieved through vectorization.

how can achieve same resolution using vectorized function rather using code below?

 i, row in df.iterrows():     ifor_val =     if <condition>:         ifor_val = something_else         df.set_value(i,'ifor',ifor_val) 

if value depends on other values in row, can't avoid iterating.

df['ifor'] = df['some_col'].apply(lambda v: if <condition> else something_else) 

this puts iteration in pandas, it's cleaner (and possibly faster).


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -