DEV Community

Cover image for 12 Ways of Applying a Function to Python Pandas DataFrame
Satish Chandra Gupta
Satish Chandra Gupta

Posted on • Edited on • Originally published at ml4devs.com

1 1

12 Ways of Applying a Function to Python Pandas DataFrame

Applying a function to rows of a Pandas DataFrame is one of the most common operations during data wrangling. There are many ways of doing it.

I plotted the performance of various ways of applying a function to each row of a Pandas DataFrame, for up to a million rows.

Performance of various alternative for applying a function to Pandas DataFrame

I was surprised to see itertuples() beating apply(), and humble list comprehension beating them both.

So far, I was using apply() whenever I found vectorization difficult. Somehow I thought it was the 2nd best option.

I have been using "%timeit" often. In this exercise, I learned how to do line-level profiling in Python and also plotting the performance over input size.

Continue reading »

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay