Search⌘ K

Looping and Aggregation

Explore methods for looping over pandas DataFrames including iteritems, iterrows, and itertuples. Understand how to apply aggregation functions along different axes and use advanced methods like agg and describe to summarize data for more effective analysis.

We'll cover the following...

Often we want to apply operations over items in a DataFrame. We may want to use looping, the apply method, or an aggregation method to do this.

For loops

We can use a for loop with a DataFrame, though we generally want to avoid for loops when doing numerical manipulation. Whenever there is a for loop with some pandas code, it means that it’s a slow operation, and we won’t be able to take advantage of the vectorization that speeds up many operations. However, sometimes a for ...