While creating conditional columns in Pandas, we tend to use the 𝐚𝐩𝐩𝐥𝐲() method almost all the time. However, 𝐚𝐩𝐩𝐥𝐲() in Pandas is nothing but a glorified for-loop. As a result, it misses the whole point of vectorization. Instead, you should use the 𝐧𝐩.𝐬𝐞𝐥𝐞𝐜𝐭() method to create conditional columns. It does the same job but is extremely fast.
Speed-up Pandas Apply 5x with NumPy
Speed-up Pandas Apply 5x with NumPy
Speed-up Pandas Apply 5x with NumPy
While creating conditional columns in Pandas, we tend to use the 𝐚𝐩𝐩𝐥𝐲() method almost all the time. However, 𝐚𝐩𝐩𝐥𝐲() in Pandas is nothing but a glorified for-loop. As a result, it misses the whole point of vectorization. Instead, you should use the 𝐧𝐩.𝐬𝐞𝐥𝐞𝐜𝐭() method to create conditional columns. It does the same job but is extremely fast.