Understand the idea
A Series pairs each value with an index label. Labels and numbered positions are different.
Illustrative data
list(readings.index)| Position | Index label | Reading |
|---|---|---|
| 0 | 101 | 12 |
| 1 | 109 | 4 |
| 2 | 103 | 19 |
Result
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.
| row | sample | hours | reading |
|---|---|---|---|
| 101 | R1 | 1 | 12 |
| 109 | R2 | 4 | 4 |
| 103 | R3 | 6 | 19 |
| 150 | R4 | 3 | 8 |
| 106 | R5 | 2 | 7 |
| 118 | R6 | 5 | 15 |
Your task · Follow
Which labels belong to the measurements?
- Select
readingfrom all rows ofdf. - Display its row labels as a list in their current order.
- Use the Series
indexattribute.
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)