После:
phone = row['Phone']
добавить:
phone = re.sub(r'[^\d]', '', phone) # removes everything except digits
assert len(phone)==10 # ensures all numbers have 10 digits
row['Phone'] = re.sub(r'(\d{3})(\d{3})(\d{4})', r'\1-\2-\3', phone) # formats the string
Или без re
модуля:
phone = ''.join(c for c in phone if c.isdigit())
row['Phone'] = '-'.join([ phone[0:3], phone[3:6], phone[6:] ])
Кстати, я бы также рекомендовал заменить это :
print(row['Name'] ,"|" ,row['Gender'] ,"|" ,row['State'] ,"|" ,row['Credit Card'] ,"|" ,row['Phone'] ,"|" ,row['Spent Past 6 Months']
с:
fields = ['Name','Gender','State','Credit Card','Phone','Spent Past 6 Months']
print('|'.join((row[field] for field in fields)))