O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DataFrame function application

Not surprisingly, DataFrames provide methods for function application. There are two methods you should be aware of, apply and applymap. apply takes a function and, by default, applies the function to the series corresponding to each column of the DataFrame. What is produced depends on what the function does. We can change the axis argument of apply so that instead of applying to columns (that is, across rows), it applies to rows (that is, across columns). applymap has a different purpose than apply. Whereas apply will evaluate the supplied function on each column and thus should be prepared to take a series, applymap will evaluate the pass function on each element of the DataFrame individually.

We could apply ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required