text_plain_output_1.png
import numpy as np

import pandas as pd

path = '../input/mobile-games-ab-testing/cookie_cats.csv'
df = pd.read_csv(path)

df.shape

df.userid = df.userid.astype(str)

df.userid.dtypes

df.version.unique()

treatment = df[df['version'] == 'gate_40']

control = df[df['version'] == 'gate_30']

treatment.shape[0]

control.shape[0]

contr_d1 = '{0:.2f}%'.format(control.retention_1.mean() * 100)
trtm_d1 = '{0:.2f}%'.format(treatment.retention_1.mean() * 100)

contr_d7 = '{0:.2f}%'.format(control.retention_7.mean() * 100)
trtm_d7 = '{0:.2f}%'.format(treatment.retention_7.mean() * 100)

retention_1_30 = control.retention_1.mean()
retention_1_40 = treatment.retention_1.mean()
obs_diff_1 = retention_1_40 - retention_1_30

diffs_1 = []
for i in range(10000):
    boot_sample = df.sample(df.shape[0], replace=True)
    gate30_df_1 = boot_sample.query('version == "gate_30"')['retention_1'].mean()
    gate40_df_1 = boot_sample.query('version == "gate_40"')['retention_1'].mean()
    diffs_1.append(gate40_df_1 - gate30_df_1)

null_vals_1 = np.random.normal(0, np.std(diffs_1), len(diffs_1))

p_val_1 = (null_vals_1 > obs_diff_1).mean()
p_form_1 = '{0:.2f}%'.format(p_val_1 * 100)
print('P-value is equal to {}'.format(p_form_1))