Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← Inspect lessons
Selecting data · Lesson 08 · 9 MIN

Read a Series: labels and values

Distinguish a Series index from its stored measurements.

  1. FollowFollow the techniqueCurrent exercise
  2. ChangeAdapt a requirement
  3. TransferChoose and combine

Understand the idea

A Series pairs each value with an index label. Labels and numbered positions are different.

Illustrative data

list(readings.index)
Series
PositionIndex labelReading
010112
11094
210319
Result[101, 109, 103]

Follow the code

readings = df["reading"]
list(readings.index)

What the syntax does

readings = df["reading"]
Select one labelled Series.
readings.index
Read the row labels, not the measurements.
list(...)
Display the labels or values as a Python list.
Labelled sensor readings
rowsamplehoursreading
101R1112
109R244
103R3619
150R438
106R527
118R6515
Your task · Follow

Which labels belong to the measurements?

  1. Select reading from all rows of df.
  2. Display its row labels as a list in their current order.
  3. Use the Series index attribute.

Setup is included in the editor.

Hint

The labels are beside the readings. Read .index, without parentheses.

Reveal solution

Keep the supplied setup and replace the Your work section with this example.

readings = df["reading"]
list(readings.index)

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display a value by leaving it on the final line.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.