.Apply on a Dataframe vs Vectorization

I am learning about map, apply and applymap methods in the Transforming data with pandas mission. I understand vectorization is applied to a whole series at once. Whereas the map, apply, and applymap methods are generally element-wise.

I just have a couple of question to confirm my understanding:

  1. The applymap method, while can apply functions element-wise to multiple columns at once, it is still two loops - one loop on the individual element level (micro) and a second loop on the column level (macro). In other words, “at once” is not performing the element-wise functions on all columns concurrently, but consecutively in the order that they are named?

  2. The apply method on a dataframe - unlike the above, this is actually applying loops concurrently for all columns (if axis = 0) or all rows (if axis = 1), but still goes row by row.

Does this have some element of vectorization because while it is going row by row, it is applying the function for all values in that axis?

1 Like

For reference, the mission tag is 345-5.

Hi @AWM007,

Does this have some element of vectorization because while it is going row by row, it is applying the function for all values in that axis?

Yes, while it’s not completely vectorized, some element of vectorization does exist. This article might be helpful to you:

Best,
Sahil