Don't Create Conditional Columns in Pandas with Apply
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.
The condition is passed as the first argument. This is followed by the result if the condition evaluates to True (second argument) and False (third argument).
Read more here: NumPy docs.
I like to explore, experiment and write about data science concepts and tools. You could connect with me on LinkedIn.