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

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.

naive.py
values = [10, 20, 30, 40, 50]
pairs = []
for i in range(len(values)):
    pairs.append([i, values[i]])
print('RESULT:', values)
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).