April 1, 2020

Given that df holds your data in a DataFrame, it has columns, and we have imported Pandas as pd:

  1. We can define a new column call is_purchase which contains “Purchase” if the existing column (click_day) is not null and “No Purchase” if it is null by applying the following code:

    1. df[‘is_purchase’] = df.click_day.apply(lambda x: ‘Purchase’ if pd.notnull(x) else ‘No Purchase’)

    2. We can count the number of users who made purchases from each group with the following code:

      1. purchase_counts = df.groupby([‘group’, ‘is_purchase’]).user_id.count( ).reset_index( )

Previous
Previous

April 7, 2020

Next
Next

March 25, 2020