Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MA - Removal Effects
def removal_effects(df, conversion_rate):
removal_effects_dict = {}
channels = [channel for channel in df.columns if channel not in ['Start',
for channel in channels:
removal_df = df.drop(channel, axis=1).drop(channel, axis=0)
for column in removal_df.columns:
row_sum = np.sum(list(removal_df.loc[column]))
null_pct = float(1) - row_sum
if null_pct != 0:
removal_df.loc[column]['Null'] = null_pct
removal_df.loc['Null']['Null'] = 1.0
removal_to_conv = removal_df[
['Null', 'Conversion']].drop(['Null', 'Conversion'], axis=0)
removal_to_non_conv = removal_df.drop(
['Null', 'Conversion'], axis=1).drop(['Null', 'Conversion'], axis=0)
removal_inv_diff = np.linalg.inv(
len(removal_to_non_conv.columns)) - np.asarray(removal_to_non_conv))
removal_dot_prod =, np.asarray(removal_to_conv))
removal_cvr = pd.DataFrame(removal_dot_prod,
removal_effect = 1 - removal_cvr / conversion_rate
removal_effects_dict[channel] = removal_effect
return removal_effects_dict
removal_effects_dict = removal_effects(trans_matrix, base_conversion_rate)

This comment has been minimized.

Copy link

@sayali1812 sayali1812 commented Jan 21, 2021
KeyError: 'Null'

hey i am getting this error. can you help me out with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment