Adding age
Given is an early stage basetable
that contains the donor ID and birth date of candidate donors. In this exercise you will learn to add the age of these donors to the basetable. The method to calculate "age" is already implemented for your convenience. Keep in mind the following timeline of the basetable:
Diese Übung ist Teil des Kurses
Intermediate Predictive Analytics in Python
Anleitung zur Übung
- Fill out the reference date.
- Add a column "age" to the
basetable
that is the age of the donor on the reference date. The functioncalculate_age
has been implemented for you. It takesdate_of_birth
andreference_date
as arguments. - Print the mean age of all donors.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Reference date
reference_date = datetime.date(____, ____, ____)
# Add age to the basetable
basetable["age"] = (pd.Series([calculate_age(____, ____)
for date_of_birth in basetable["date_of_birth"]]))
# Calculate mean age
print(round(basetable["____"].____()))