5 (1)

5 (1)

#### Overview of this book

Python, a multi-paradigm programming language, has become the language of choice for data scientists for visualization, data analysis, and machine learning. Hands-On Data Analysis with NumPy and Pandas starts by guiding you in setting up the right environment for data analysis with Python, along with helping you install the correct Python distribution. In addition to this, you will work with the Jupyter notebook and set up a database. Once you have covered Jupyter, you will dig deep into Python’s NumPy package, a powerful extension with advanced mathematical functions. You will then move on to creating NumPy arrays and employing different array methods and functions. You will explore Python’s pandas extension which will help you get to grips with data mining and learn to subset your data. Last but not the least you will grasp how to manage your datasets by sorting and ranking them. By the end of this book, you will have learned to index and group your data for sophisticated data analysis and manipulation.
Title Page
Packt Upsell
Contributors
Preface
Free Chapter
Setting Up a Python Data Analysis Environment
Diving into NumPY
Operations on NumPy Arrays
pandas are Fun! What is pandas?
Arithmetic, Function Application, and Mapping with pandas
Managing, Indexing, and Plotting
Other Books You May Enjoy
Index

## Hierarchical indexing

We have come a long way, but we're not quite done yet. We need to talk about hierarchical indexing. In this section, we look at hierarchical indices, why they are useful, how they are created, and how they can be used.

So, what are hierarchical indices? They bring additional structure to an index and exist in pandas as `MultiIndex` class objects, but they are still an index that can be assigned to a series or DataFrame. With a hierarchical index, we think of rows in a DataFrame, or elements in a series, as uniquely identified by combinations of two or more indices. These indices have a hierarchy, and selecting an index at one level will select all elements with that level of the index. We can go on a more theoretical path and claim that when we have a `MultiIndex`, the dimensionality of the table increases. It behaves, not as a square on which data exists, but as a cube, or at least it could.

A hierarchical index is used when we want additional structure on the index without...