Когда я писал этот код, я считал, что вам нужна маска с [two digits]-[three digits]
для почтовых индексов, а не просто черточка внутри или непустое поле.
import re
import csv
# Compile our regexp
regexp = re.compile(r'[0-9]{2}-[0-9]{3}')
# Read the CSV and load it into memory
reader = csv.DictReader(open('sample.csv'))
table = list(reader)
# Iterate for rows
for row in table:
# Check if the postal code is fit to our regexp
if regexp.match(row['POSTAL_CD']):
row['COUNTRY'] = 'PL'
# Write the result
with open('result.csv', 'w') as f:
writer = csv.DictWriter(f, fieldnames=['', 'POSTAL_CD', 'COUNTRY'])
writer.writeheader()
writer.writerows(table)