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

php - Autoloader issue not returning Class -

java - How to put two numbers separated by a space into two different arrays -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -