liveBook · Manning

Series

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

A pandas Series is a one-dimensional labeled array that can hold values of a common or compatible data type.

A pandas Series is a one-dimensional sequence of values paired with an index. Think of it as one labeled measurement: monthly test scores, daily temperatures, taxi passenger counts, or a single column from a table. A DataFrame is largely a collection of Series that share an index, so understanding Series makes column-wise pandas work easier to reason about. section 1.0 section 2.0

Figure 1.1 Each of a data frame’s columns is a series.

Use the column view to connect a one-dimensional Series to the two-dimensional DataFrame it helps compose. section 1.0

Create a Series from an iterable such as a Python list or NumPy array, optionally supplying labels as its index. The index is more than display metadata: use .loc to retrieve by label and .iloc to retrieve by position. Labels can repeat; selecting a repeated label then returns every matching value rather than a single scalar. section 1.3 section 1.19

Treat the index as the organizing principle for common Series operations:

  • Select values by labels with .loc, by integer positions with .iloc, or by slices when comparing parts of a sequence. section 1.3
  • Combine two Series with vectorized arithmetic; matching happens by index labels, not by their physical positions. section 1.7
  • Combine a Series with one scalar through broadcasting, producing a new Series with the same index. section 1.7
  • Build a boolean Series with comparisons, then use it as a mask to select or update only True positions. section 1.13

Analyze and adjust labeled test scores

For scores indexed by month, calculate a yearly mean, compare first- and second-half averages, and measure improvement. To shift the whole Series toward a target average, compute the scalar difference between the target and s.mean(), then add it to s; broadcasting applies that adjustment to every labeled score. section 1.2 section 1.7

Series methods return either a scalar or another Series. For example, mean returns one number, while describe returns a Series of count, mean, standard deviation, minimum, quartiles, median, and maximum. This return shape matters: a returned Series can be indexed, sorted, or passed into further operations. section 1.15 section 1.0

A one-column CSV can become a Series by reading it into a one-column DataFrame and calling squeeze. From there, value_counts creates a new Series whose index holds distinct observed values and whose values hold frequencies; normalize=True turns those counts into proportions. section 1.23

Filter and summarize taxi rides

Load passenger counts, use value_counts(normalize=True) to compare one- and six-passenger ride proportions, or turn ride distances into short, medium, and long categories and count each category. These tasks favor vectorized Series operations over explicit Python loops. section 1.22 section 1.26

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Works through construction, labeled and positional retrieval, masks, vectorized arithmetic, statistics, file loading, and frequency analysis.
Examples
Uses monthly test scores, random temperatures, normally distributed values, and New York City taxi passenger and distance data.
What it assumes
Assumes familiarity with pandas and uses Python lists plus NumPy arrays and random-number generators to construct examples.
What you can do after
Apply it via pandas to create, index, filter, summarize, align, and categorize one-dimensional data.
How it connects
Connects indexes, DataFrames, vectorized operations, broadcasting, boolean indexing, descriptive statistics, and groupby results.

Also explained in

Compare how 4 books explain Series →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.