3 Series methods

 

This chapter covers

  • Importing CSV data sets with the read_csv function
  • Sorting Series values in ascending and descending order
  • Retrieving the largest and smallest values in a Series
  • Counting occurrences of unique values in a Series
  • Invoking a function with every value in a Series

In chapter 2, we began exploring the Series object, a one-dimensional labeled array of homogeneous values. We populated our Series with data from different sources, including lists, dictionaries, and NumPy ndarrays. We observed how pandas assigned each Series value an index label and an index position. We learned how to apply mathematical operations to Series.

With the basics under our belt, we’re ready to explore some real-world data sets! In this chapter, we’ll introduce lots of advanced Series operations, including sorting, counting, and bucketing. We’ll also start to see how these methods can help us derive insights from our data. Let’s dive in.

3.1 Importing a data set with the read_csv function

A CSV is a plain-text file that separates each row of data with a line break and each row value with a comma. The first row in the file holds the column headers for the data. This chapter has three CSV files for us to play with:

3.2 Sorting a Series

 
 
 
 

3.2.1 Sorting by values with the sort_values method

 
 
 

3.2.2 Sorting by index with the sort_index method

 
 
 
 

3.2.3 Retrieving the smallest and largest values with the nsmallest and nlargest methods

 
 

3.3 Overwriting a Series with the inplace parameter

 
 
 

3.4 Counting values with the value_counts method

 
 
 
 

3.5 Invoking a function on every Series value with the apply method

 
 
 

3.6 Coding challenge

 
 
 

3.6.1 Problems

 
 
 

3.6.2 Solutions

 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest