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
Post a Comment