Aan de slagGa gratis aan de slag

Pivoting our data

As you saw, there does seem to be an increase in the number of purchases by purchasing users within their first week. Let's now confirm that this is not driven only by one segment of users. We'll do this by first pivoting our data by 'country' and then by 'device'. Our change is designed to impact all of these groups equally.

The user_purchases data from before has been grouped and aggregated by the 'country' and 'device' columns. These objects are available in your workspace as user_purchases_country and user_purchases_device.

As a reminder, .pivot_table() has the following signature:

pd.pivot_table(data, values, columns, index)

Deze oefening maakt deel uit van de cursus

Customer Analytics and A/B Testing in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Pivot the data
country_pivot = pd.pivot_table(user_purchases_country, values=['____'], columns=['____'], index=['____'])
print(country_pivot.head())
Code bewerken en uitvoeren