Build a labeled column by pairing each value in a list with its positional index. A loop creates (index, value) pairs explicitly, making the two-part structure of a Series concrete before the one-call pandas version.

By hand

Loop over each index i from 0 to len(values) - 1, building a list of [i, value] pairs. Each pair represents one entry in the labeled column — a position label and the value at that position.

naive.py
Replay: real traced execution (multi-file project)
values = [10, 20, 30, 40, 50]
pairs = []
for i in range(len(values)):
    pairs.append([i, values[i]])
print('RESULT:', values)
  1. values ← [10, 20, 30, 40, 50]

    1values = [10, 20, 30, 40, 50]2pairs = []
    values this step[10, 20, 30, 40, 50]values
  2. pairs ← []

    1values = [10, 20, 30, 40, 50]2pairs = []3for i in range(len(values)):
    values this step[]pairs
  3. i ← 0

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
    values this step0i
  4. pairs ← [[0, 10]]

    3for i in range(len(values)):4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this step[] [[0, 10]]pairs
  5. i ← 1

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
    values this step0 1i
  6. pairs ← [[0, 10], [1, 20]]

    3for i in range(len(values)):4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this step[[0, 10]] [[0, 10], [1, 20]]pairs
  7. i ← 2

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
    values this step1 2i
  8. pairs ← [[0, 10], [1, 20], [2, 30]]

    3for i in range(len(values)):4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this step[[0, 10], [1, 20]] [[0, 10], [1, 20], [2, 30]]pairs
  9. i ← 3

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
    values this step2 3i
  10. pairs ← [[0, 10], [1, 20], [2, 30], [3, 40]]

    3for i in range(len(values)):4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this step[[0, 10], [1, 20], [2, 30]] [[0, 10], [1, 20], [2, 30], [3, 40]]pairs
  11. i ← 4

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
    values this step3 4i
  12. pairs ← [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50]]

    3for i in range(len(values)):4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this step[[0, 10], [1, 20], [2, 30], [3, 40]] [[0, 10], [1, 20], [2, 30], [3, 40], [4, 50]]pairs
  13. for i in range(len(values)):

    2pairs = []3for i in range(len(values)):4    pairs.append([i, values[i]])
  14. stdout ← RESULT: [10, 20, 30, 40, 50]

    4    pairs.append([i, values[i]])5print('RESULT:', values)
    values this stepRESULT: [10, 20, 30, 40, 50]stdout

With pandas

pd.Series(values) wraps the list in a Series with a default RangeIndex (0, 1, 2, ...). The snapshot shows the index, values, and dtype as stable labeled lines.

library.py
import pandas as pd
from dalib.display import set_display
set_display()

values = [10, 20, 30, 40, 50]
s = pd.Series(values)
print('index:', s.index.tolist())
print('values:', s.tolist())
print('dtype:', s.dtype)
print('RESULT:', s.tolist())
index: [0, 1, 2, 3, 4]
values: [10, 20, 30, 40, 50]
dtype: int64
RESULT: [10, 20, 30, 40, 50]

Implementation notes

  • A Series has two components: an index (the labels) and a values array. The default index is RangeIndex(0, n), equivalent to the positional indices built in the hand-written loop.
  • s.tolist() converts the values array to a plain Python list, giving a stable RESULT independent of pandas display options.
  • s.dtype is the dtype of the values array — the same numpy dtype system used in the NumPy chapters. Pandas stores column data as numpy arrays internally.
  • Index and values are shown via .tolist() here because raw Series.__repr__ output varies with pandas display options (terminal width, float format, etc).