Get startedGet started for free

Calculate an event target

======= You are organising a charity event and want to predict which donors are most likely to attend this event. You organized a similar event in the past, so you can use that information to construct a predictive model. Given is a list population with unique donor ids for this basetable and a list attend_event with donors in the population that attended this past event. In this exercise you will construct a basetable with two columns: the donor_id and the target, which is 1 if the donor attended the event and 0 otherwise.

This exercise is part of the course

Intermediate Predictive Analytics in Python

View Course

Exercise instructions

  • Construct a pandas dataframe basetable that has one row for each donor in population and one column donor_id with the donor's ID.
  • Add the target as a column to the basetable. The target is 1 if the donor attended the event and 0 otherwise.
  • Calculate and print the target incidence, i.e. the number of times the target is 1 divided by the number of rows in the basetable.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Basetable with one column: donor_id
basetable = pd.DataFrame(____, columns=["____"])

# Add target to the basetable
basetable["target"] = pd.Series([____ if donor_id in ____ else ____ for donor_id in basetable["donor_id"]])

# Calculate and print the target incidence
print(round(____["____"].sum() / len(____), 2))
Edit and Run Code