Back to Chapters
Chapter Progress: 0 %0 / 6 Lessons Read
‹›

1. Introduction to pandas

1.2 Series: one labelled column

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      A Series holds values in order, each with a label called the index. By default the labels are 0, 1, 2 …, just like list positions.

      • s = pd.Series([250, 400, 150]) creates the Series
      • s[0] reads the value with label 0
      • s.sum(), s.mean() and s.max() summarise the whole column
      • s * 2 doubles every value at once, with no loop

      You can choose your own labels: pd.Series([250, 400], index=["mon", "tue"]), then read s["tue"].

      List vs Series

      • [250, 400, 150] * 2 → repeats the list: 6 items
      • pd.Series([250, 400, 150]) * 2 → doubles each value: 500, 800, 300
      Must Know:

      Maths on a Series works on every value at once. This is called vectorised work, and it’s why pandas is fast on big data.

      How it fits together

      1. mon · 250
      2. tue · 400
      3. wed · 150

      Step through the code

      Python

      import pandas as pdsales = pd.Series([250, 400, 150], index=["mon", "tue", "wed"])print(sales["tue"])print(sales.sum())print(sales * 2)

      Output

      400
      800
      mon    500
      tue    800
      wed    300
      dtype: int64

      Practice in pandas

      Create a Series marks with 60, 75 and 90, then print the mean.

      Expected output
      75.0

      Reference solution
      import pandas as pd
      marks = pd.Series([60, 75, 90])
      print(marks.mean())

      Question 1 · Easy

      s = pd.Series([3, 5, 7]). What is s[0]?

      Question 2 · Medium

      s = pd.Series([10, 20, 30]). What does s.sum() give?

      Question 3 · Hard

      s = pd.Series([1, 2, 3]). What does (s * 2).tolist() give?

      Key takeaways

      A Series is one column of values with labels. Maths and summaries like sum() and mean() work on the whole column at once.

      Lesson 2 of 13

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousSeries: one labelled column
      Save your progress free for 1 month. Start free · Log in