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 ...

Get Hands-On Data Analysis with NumPy and pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.