Module 3 · pandas · Lesson 15 of 66
Meet pandas: the Series
A labeled column of data, and why labels make math line up.
In this lesson · about 12 minutes
- Import pandas as pd
- Make a Series from a list, array or dictionary
- Look up values by label and see how labels align
pandas is the tool data scientists reach for most. Think of it as a very powerful spreadsheet you control with code: it reads files, cleans messy data, filters, groups, joins tables and summarizes, on millions of rows if you need it.
This module goes in order: Series, DataFrames, missing data, groupby, combining tables, handy operations, and reading and writing files. Then you'll put it all to work on two real data sets.
A Series is one column of data with a label (the index) for every value. It's built on a NumPy array, but where an array only has positions 0, 1, 2…, a Series can be labeled with anything, such as names or dates.
Using the index
Look up a value by its label, like a dictionary: ser['USA']. When you do math with two Series, pandas matches values by label, not by position. A label that's only in one of them has nothing to pair with, so the result there is NaN (missing).
Exercise
Rent by city
Make a Series called rent from the dictionary, then set la to the value for 'Los Angeles'.
Check your understanding0 of 1 correct
Quiz score: 0 of 1
Exercises solved: 0 of 1
Noviq Academy's Data Science course is free and for learning. Python runs in your browser with Pyodide, which downloads about 20 MB the first time, plus a few more for scikit-learn. Your code and progress stay on this device. The salaries data is a sample of San Francisco's public pay records; the purchases, customers, housing, advertising and classified data are made up. The Titanic, tips, flights and iris data sets come from Seaborn's examples; the maps use public 2011 to 2014 US and world figures. The 911 data is a 20,000-call sample of Montgomery County, Pennsylvania's public 911 records; the movie ratings are the MovieLens 100K data from GroupLens Research; the reviews are a 3,000-review sample from the Yelp Dataset Challenge; the loans are public LendingClub data; the colleges are the College data from An Introduction to Statistical Learning; the bank notes, kyphosis and breast cancer data come from the UCI Machine Learning Repository. Spark and TensorFlow can't run in a browser, so those lessons use stand-ins that run here, and show the code for the real tools.