Grouping using index levels

It is possible to group by using the values in the index instead of the columns. The sensor data is well suited for a hierarchical index, which can be used to demonstrate this concept. Let's set up a form of this data with a hierarchical index consisting of the sensor and axis columns:

Grouping can now be performed using the various levels of the hierarchical index. This code will group by index level 0 (the sensor names):

Grouping by multiple levels can be performed by passing the levels in a list. And if MultiIndex ...

Get Learning pandas - Second Edition 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.