I think np.where
is faster because use numpy
array vectorized way and pandas is built on this arrays.
df.apply
is slow, because it use loops
.
vectorize
operations are the fastest, then cython routines
and then apply
.
See this answer with better explanation of developer of pandas – Jeff.