Adding the donor segment
Besides age, you also want to add the segment of a donor to the basetable. A selected group of donors that has made many donations in the past is assigned a segment: bronze, silver or gold. Given is an early stage basetable
and a pandas dataframe segments
that contains the segments for a selected group of the donors in the basetable. In this exercise you will add the segment to the basetable
.
You can left join two pandas dataframes using the following code:
merged_df = pd.merge(df1, df2, on=["merge_id"],how="left")
Este ejercicio forma parte del curso
Intermediate Predictive Analytics in Python
Instrucciones del ejercicio
- The donor id column is "donor_id" both in
segments
andbasetable
. Add the segment to thebasetable
. - Count the number of donors in each segment.
- Count the number of donors with no segment assigned.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Add the donor segment to the basetable
basetable = pd.merge(____, ____, on =["____"], how="____")
# Count the number of donors in each segment
basetable.groupby("____").____()
# Count the number of donors with no segment assigned
print(basetable["segment"].____().____())