chapter three

3 Series Methods

 

This chapter covers:

  • Importing CSV datasets
  • Sorting Series values in ascending and descending order
  • Retrieving the largest and smallest values in a Series
  • Mutating a Series inplace
  • Counting occurrences of unique values in a Series
  • Applying an operation to every value in a Series

In the previous chapter, we began our exploration of the Series object, a one-dimensional labelled array. We populated our Series from our own sources of data including lists, dictionaries, and NumPy's ndarray object. It's now time to dive into some diverse real-world datasets! There are three files for us to explore, all of which are stored in the CSV (Comma Separated Values) file format:

  • pokemon.csv, an index of 800+ Pokémon, the popular Nintendo cartoon monsters that took the world by storm in the 1990s and now make up the highest grossing franchise of all time. Each Pokémon has one or more types such as Fire, Water, or Grass.
  • google_stock.csv, a list of daily stock prices in US dollars for the technology company Google from its debut in August 2004 to October 2019
  • revolutionary_war.csv, a record of battles during the American Revolutionary War. Each conflict is associated with a start date and a U.S. state. Because certain battles do not have a definitive start date or were not fought on U.S. territory, this data set contains missing / absent values.

3.1   Importing a Dataset with the read_csv Method

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: Deriving Insights from a Series

3.6.1   Problem

3.6.2   Solution

3.7   Summary