From the course: pandas Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Iterate through a group

Iterate through a group - pandas Tutorial

From the course: pandas Essential Training

Start my 1-month free trial

Iterate through a group

- [Narrator] We can iterate through groups. As we mentioned earlier, each of these groups are data frames. What we can do here, is to print out the key and then print out the rows corresponding to that key. As an example, on the olympics dataset we are working on, if we group by each olympic here, then the key would be the olympic edition or year, and the group portion would be all of the rows corresponding to that edition. Then Groupby prints the next olympic edition, followed by all of the rows corresponding to that edition. Let's take a look in our Jupyter notebook. So what we want to do here is to look through the Groupby object, for group key group value in, and then a Groupby object which is Edition in this case, we are grouping by edition. This is just a very simple Python script. I want to print the group key and I want to print the group value. And I change that to value, and the group value and let's run this. And basically what we see here is what we saw in the list command…

Contents