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

## Index sorting

When talking about sorting, we need to think about what exactly we are sorting. There are rows, columns, their indices, and the data they contain. Let's first look at index sorting. We can use the `sort_index` method to rearrange the rows of a DataFrame so that the row indices are in order. We can also sort the columns by setting the access parameter of `sort_index` to `1`. By default, sorting is done in ascending order; later rows have larger values than earlier rows, but we can change this behavior by setting the ascending value of the `sort_index` value to false. This sorts in descending order. By default, this is not done in place; you need to set the in place argument of `sort_index` to true for that.

While I have emphasized sorting for DataFrames, sorting a series is effectively the same. Let's see an example. After loading in NumPy and pandas, we create a DataFrame with values to sort, shown in the following screenshot:

Let's sort the index; notice that this is not done in place...