Convert date strings from a regional format (MM/DD/YYYY) into ISO 8601 strings (YYYY-MM-DD). By hand, parse each string with datetime.strptime using an explicit format code and call .isoformat() on the result. With pandas, pd.to_datetime infers the format and the datetime64 Series normalises to ISO via .dt.strftime.

By hand

Pass the format string '%m/%d/%Y' to datetime.strptime so each token maps to the right field. Calling .date() drops the time component, and .isoformat() produces the canonical YYYY-MM-DD string. The datetime. date object is not a traced type — the trace shows result growing with the ISO strings directly.

naive.py
Replay: real traced execution (multi-file project)
import datetime
date_strs = ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']
result = []
for s in date_strs:
    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
    result.append(d.isoformat())
print('RESULT:', result)
  1. import datetime

    1import datetime2date_strs = ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']
  2. date_strs ← ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']

    1import datetime2date_strs = ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']3result = []
    values this step['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']date_strs
  3. result ← []

    2date_strs = ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']3result = []4for s in date_strs:
    values this step[]result
  4. s ← '05/10/2023'

    3result = []4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
    values this step'05/10/2023's
  5. d = datetime.datetime.strptime(s, '%m/%d/%Y').date()

    4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())
  6. result ← ['2023-05-10']

    5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())7print('RESULT:', result)
    values this step[] ['2023-05-10']result
  7. s ← '08/25/2023'

    3result = []4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
    values this step'05/10/2023' '08/25/2023's
  8. d = datetime.datetime.strptime(s, '%m/%d/%Y').date()

    4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())
  9. result ← ['2023-05-10', '2023-08-25']

    5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())7print('RESULT:', result)
    values this step['2023-05-10'] ['2023-05-10', '2023-08-25']result
  10. s ← '01/03/2024'

    3result = []4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
    values this step'08/25/2023' '01/03/2024's
  11. d = datetime.datetime.strptime(s, '%m/%d/%Y').date()

    4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())
  12. result ← ['2023-05-10', '2023-08-25', '2024-01-03']

    5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())7print('RESULT:', result)
    values this step['2023-05-10', '2023-08-25'] ['2023-05-10', '2023-08-25', '2024-01-03']result
  13. s ← '06/18/2024'

    3result = []4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
    values this step'01/03/2024' '06/18/2024's
  14. d = datetime.datetime.strptime(s, '%m/%d/%Y').date()

    4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())
  15. result ← ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']

    5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()6    result.append(d.isoformat())7print('RESULT:', result)
    values this step['2023-05-10', '2023-08-25', '2024-01-03'] ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']result
  16. for s in date_strs:

    3result = []4for s in date_strs:5    d = datetime.datetime.strptime(s, '%m/%d/%Y').date()
  17. stdout ← RESULT: ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']

    6    result.append(d.isoformat())7print('RESULT:', result)
    values this stepRESULT: ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']stdout

With pandas

pd.to_datetime(df['d']) infers the MM/DD/YYYY format from the data and returns a datetime64[ns] Series. .dt.strftime('%Y-%m-%d') converts each timestamp back to a plain ISO string for the RESULT.

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

date_strs = ['05/10/2023', '08/25/2023', '01/03/2024', '06/18/2024']
df = pd.DataFrame({'d': date_strs})
s = pd.to_datetime(df['d'])
result = s.dt.strftime('%Y-%m-%d').tolist()
print('index:', s.index.tolist())
print('dtype:', s.dtype)
print('values:', s.dt.strftime('%Y-%m-%d').tolist())
print('RESULT:', result)
index: [0, 1, 2, 3]
dtype: datetime64[ns]
values: ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']
RESULT: ['2023-05-10', '2023-08-25', '2024-01-03', '2024-06-18']

Implementation notes

  • pd.to_datetime infers many common formats automatically. For ambiguous inputs (e.g. '01/02/03') or production pipelines, pass format='%m/%d/%Y' to be explicit and avoid mis-parsing.
  • Date equality: both halves produce plain Python strings so RESULT comparison is straightforward string equality — no datetime.date vs Timestamp conversion needed.
  • Cross-reference: parse-date-column (python-pandas ch09) for the companion lesson covering .dt accessor workflows after parsing; this lesson focuses on the format-normalization step for messy inputs.