LoslegenKostenlos loslegen

Calculate average price

You will now calculate the average price metric and analyze if there are any differences in shopping patterns across time and across cohorts.

The online dataset has been loaded to you with monthly cohorts and cohort index assigned from this lesson. Feel free to print it to the Console.

Diese Übung ist Teil des Kurses

Customer Segmentation in Python

Kurs anzeigen

Anleitung zur Übung

  • Create a groupby object and pass the monthly cohort and cohort index as a list.
  • Select the unit price column, calculate the average, and store it to cohort_data.
  • Reset the index of cohort_data DataFrame.
  • Create a pivot with monthly cohort in the index, cohort index in the columns and the unit price in the values, and print the result.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Create a groupby object and pass the monthly cohort and cohort index as a list
grouping = online.groupby([____, ____]) 

# Calculate the average of the unit price column
cohort_data = grouping[____].____()

# Reset the index of cohort_data
cohort_data = cohort_data.____()

# Create a pivot 
average_price = cohort_data.____(index=____, columns=____, values=____)
print(average_price.round(1))
Code bearbeiten und ausführen