Extract one column from a list of row-records by looping and appending each record's field to a collector list. With pandas, df['col'] performs the same extraction in one step and returns a Series — a typed, indexed 1D view of that column rather than a raw list.

By hand

Loop over each row-record r in the list and append r['score'] to col, watching the column list grow one entry per record.

naive.py
Replay: real traced execution (multi-file project)
# trace: ignore records
records = [
    {'name': 'al', 'age': 20, 'score': 80},
    {'name': 'bo', 'age': 25, 'score': 90},
    {'name': 'cy', 'age': 22, 'score': 70},
    {'name': 'di', 'age': 28, 'score': 85},
]
col = []
for r in records:
    col.append(r['score'])
print('RESULT:', col)
  1. {'name': 'al', 'age': 20, 'score': 80},

    2records = [3    {'name': 'al', 'age': 20, 'score': 80},4    {'name': 'bo', 'age': 25, 'score': 90},
  2. {'name': 'bo', 'age': 25, 'score': 90},

    3{'name': 'al', 'age': 20, 'score': 80},4{'name': 'bo', 'age': 25, 'score': 90},5{'name': 'cy', 'age': 22, 'score': 70},
  3. {'name': 'cy', 'age': 22, 'score': 70},

    4{'name': 'bo', 'age': 25, 'score': 90},5{'name': 'cy', 'age': 22, 'score': 70},6{'name': 'di', 'age': 28, 'score': 85},
  4. {'name': 'di', 'age': 28, 'score': 85},

    5    {'name': 'cy', 'age': 22, 'score': 70},6    {'name': 'di', 'age': 28, 'score': 85},7]
  5. records = [

    1# trace: ignore records2records = [3    {'name': 'al', 'age': 20, 'score': 80},
  6. col ← []

    7]8col = []9for r in records:
    values this step[]col
  7. r ← {'name': 'al', 'age': 20, 'score': 80}

    8col = []9for r in records:10    col.append(r['score'])
    values this step{'name': 'al', 'age': 20, 'score': 80}r
  8. col ← [80]

    9for r in records:10    col.append(r['score'])11print('RESULT:', col)
    values this step[] [80]col
  9. r ← {'name': 'bo', 'age': 25, 'score': 90}

    8col = []9for r in records:10    col.append(r['score'])
    values this step{'name': 'al', 'age': 20, 'score': 80} {'name': 'bo', 'age': 25, 'score': 90}r
  10. col ← [80, 90]

    9for r in records:10    col.append(r['score'])11print('RESULT:', col)
    values this step[80] [80, 90]col
  11. r ← {'name': 'cy', 'age': 22, 'score': 70}

    8col = []9for r in records:10    col.append(r['score'])
    values this step{'name': 'bo', 'age': 25, 'score': 90} {'name': 'cy', 'age': 22, 'score': 70}r
  12. col ← [80, 90, 70]

    9for r in records:10    col.append(r['score'])11print('RESULT:', col)
    values this step[80, 90] [80, 90, 70]col
  13. r ← {'name': 'di', 'age': 28, 'score': 85}

    8col = []9for r in records:10    col.append(r['score'])
    values this step{'name': 'cy', 'age': 22, 'score': 70} {'name': 'di', 'age': 28, 'score': 85}r
  14. col ← [80, 90, 70, 85]

    9for r in records:10    col.append(r['score'])11print('RESULT:', col)
    values this step[80, 90, 70] [80, 90, 70, 85]col
  15. for r in records:

    8col = []9for r in records:10    col.append(r['score'])
  16. stdout ← RESULT: [80, 90, 70, 85]

    10    col.append(r['score'])11print('RESULT:', col)
    values this stepRESULT: [80, 90, 70, 85]stdout

With pandas

df['score'] selects the column by name and returns it as a Series. The snapshot shows the Series index, values, dtype, and the column name stored on the Series itself.

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

records = [
    {'name': 'al', 'age': 20, 'score': 80},
    {'name': 'bo', 'age': 25, 'score': 90},
    {'name': 'cy', 'age': 22, 'score': 70},
    {'name': 'di', 'age': 28, 'score': 85},
]
df = pd.DataFrame(records)
col = df['score']
print('index:', col.index.tolist())
print('values:', col.tolist())
print('dtype:', col.dtype)
print('name:', col.name)
print('RESULT:', col.tolist())
index: [0, 1, 2, 3]
values: [80, 90, 70, 85]
dtype: int64
name: score
RESULT: [80, 90, 70, 85]

Implementation notes

  • df['col'] returns a Series — the column retains the DataFrame's index and a .name attribute equal to the column label.
  • df[['col']] (double brackets) returns a single-column DataFrame instead. The distinction matters when passing the result to functions that expect a 2D structure.
  • The returned Series shares data with the DataFrame by default (no copy). Use .copy() if you need an independent column to modify without affecting the original DataFrame.
  • To select multiple columns at once, pass a list: df[['age', 'score']] returns a DataFrame with just those two columns.