apply is one of the most incorrectly used functions in pandas. Chances are if you are using it, you shouldn’t be. This is because apply “applies” the function to each row or each column in the data set effectively breaking one of the cardinal rules of using pandas: do not iterate over the data set. In this chapter, we’ll explore when apply is the right choice and present alternative solutions for when it’s not.
When not to use apply
For those comfortable with basic programing features, iteration is a familiar way to manipulate data. We think to ourselves: I would like to run this operation on every ...