main_10.py 699 B

1234567891011121314151617181920
  1. def pseudonymize_row(row):
  2. """
  3. Replace some identifying information with others:
  4. - Fake name
  5. - Birthdate is replaced with the age
  6. """
  7. anonymized_row = row.copy()
  8. # using Faker (https://faker.readthedocs.io/en/master/), we generate fake names
  9. if anonymized_row['Gender'] == 'Female':
  10. anonymized_row['Fullname'] = faker.name_female()
  11. else:
  12. anonymized_row['Fullname'] = faker.name_male()
  13. del anonymized_row['Birthdate']
  14. birthdate = datetime.strptime(row['Birthdate'], '%Y-%m-%d')
  15. age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
  16. anonymized_row['Age'] = age
  17. return anonymized_row