Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "import IPython.core.display as di\n",
- "\n",
- "# This line will hide code by default when the notebook is exported as HTML\n",
- "di.display_html('<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>', raw=True)\n",
- "\n",
- "# This line will add a button to toggle visibility of code blocks, for use with the HTML export version\n",
- "di.display_html('''<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>''', raw=True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "from IPython.display import display, HTML\n",
- "from itertools import combinations, product"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "from jarvis.brain.utility.data_preparation import (get_metrics_single_date, get_metrics_date_range)\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "from sklearn import tree\n",
- "import pydotplus\n",
- "global_metrics = ['ga_cpt', 'fb_spend', 'ga_transactions', 'ga_revenue']\n",
- "goal_metric = 'ga_cpt'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "start = '2017-02-21'\n",
- "end = '2017-03-21'\n",
- "df = get_metrics_date_range(119, 'ad', start, end, global_metrics, custom_tags=True, active=False)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df_g = df"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df= df[df['App Type'] == 'Web']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "excluded_tags = ['Campaigns', 'ad_id', 'Image', 'Adsets', 'start_date', '_id', 'Ads',\n",
- " 'end_date', 'Active Ads Count in Adset', 'Active Adsets Count in Campaign', 'Labels', 'audience type', 'audience category', 'Product Set',\n",
- " 'Prominent Text', 'Dominant Color', 'DominantColor', 'ProminentText', 'NumberofFaces', 'Number of Faces', 'Sale', 'name', 'Carousel Count' , 'Ad Format']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "def exclude_single_dominant_tag(tags, df):\n",
- " all_tags = []\n",
- " total_spend = df.fb_spend.sum()\n",
- " for tag in tags:\n",
- " grp = df.groupby(tag).sum()\n",
- " grp['prop'] = grp.fb_spend / total_spend\n",
- " if pd.np.max(grp['prop']) > 0.95:\n",
- " print(tag)\n",
- " continue\n",
- " all_tags.append(tag)\n",
- " return all_tags\n",
- "def clean_tags(df, excluded_tags, global_metrics):\n",
- " all_tags = list(set(df.columns) - set(global_metrics) - set(excluded_tags))\n",
- " all_tags = [tag for tag in all_tags if len(df[df[tag] != 'None'][tag].unique()) > 1]\n",
- " all_tags = [tag for tag in all_tags if df[tag].count() > 0.25*len(df)]\n",
- " all_tags = exclude_single_dominant_tag(all_tags, df) \n",
- " return all_tags"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Behaviors\n",
- "User OS\n"
- ]
- }
- ],
- "source": [
- "all_tags = clean_tags(df, excluded_tags, global_metrics)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Tags after cleanup"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "['Audience Types',\n",
- " 'Gender',\n",
- " 'Device Platforms',\n",
- " 'Landing Pages',\n",
- " 'Lookalike Types',\n",
- " 'Facebook Positions',\n",
- " 'Audience Strategy',\n",
- " 'Interests',\n",
- " 'Custom Audiences',\n",
- " 'Ad Type',\n",
- " 'Locations',\n",
- " 'Optimization Goal',\n",
- " 'Campaign Objective',\n",
- " 'strategy',\n",
- " 'Age Range',\n",
- " 'Current Adsets',\n",
- " 'Billing Event',\n",
- " 'AdsetStrategy',\n",
- " 'Publisher Platforms']"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "all_tags"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df_org = df.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df = df_org[df_org['App Type'] == 'Web']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "overall_cpt = df.fb_spend.sum() / df.ga_transactions.sum()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df_global = df.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "total_spend = df_global.fb_spend.sum()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "tag_scores = {}\n",
- "for tag in all_tags:\n",
- " temp = df.groupby([tag]).sum()\n",
- " temp['prop'] = temp['fb_spend'] / total_spend\n",
- " tag_scores[tag] = temp[temp.index != 'None']['prop'].mean()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Scores"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[('Interests', 0.012374212466183187),\n",
- " ('Landing Pages', 0.016936776591743516),\n",
- " ('Custom Audiences', 0.025144310123355166),\n",
- " ('Lookalike Types', 0.0362420481952802),\n",
- " ('Age Range', 0.07142857142857138),\n",
- " ('Audience Types', 0.12491133392877618),\n",
- " ('strategy', 0.1595410051068123),\n",
- " ('Facebook Positions', 0.16368058291676418),\n",
- " ('Locations', 0.16666666666666674),\n",
- " ('Publisher Platforms', 0.2),\n",
- " ('Optimization Goal', 0.24999999999999992),\n",
- " ('Campaign Objective', 0.24999999999999997),\n",
- " ('Current Adsets', 0.26607416518977656),\n",
- " ('AdsetStrategy', 0.3059956515591048),\n",
- " ('Audience Strategy', 0.3333333333333332),\n",
- " ('Gender', 0.33333333333333326),\n",
- " ('Device Platforms', 0.3333333333333334),\n",
- " ('Ad Type', 0.33333333333333387),\n",
- " ('Billing Event', 0.4999999999999998)]"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import operator\n",
- "sorted(tag_scores.items(), key=operator.itemgetter(1))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "score_df = pd.DataFrame().from_dict(tag_scores, orient='index')\n",
- "score_df = score_df.rename(columns = {0:'score'})"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "score_df = score_df[pd.notnull(score_df['score'])]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "num_levels = 4"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "from sklearn.cluster import KMeans\n",
- "from sklearn import preprocessing\n",
- "\n",
- "train = score_df[pd.notnull(score_df['score'])].values\n",
- "train = preprocessing.scale(train)\n",
- "kmeans_model = KMeans(n_clusters=num_levels, random_state=1).fit(train)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 23,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "score_df['level'] = kmeans_model.labels_"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "score_levels = {}\n",
- "for level in range(num_levels):\n",
- " score_levels[level] = score_df[score_df['level'] == level]['score'].mean()\n",
- "\n",
- "levels = sorted(score_levels.items(), key=operator.itemgetter(1), reverse=True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "global_tag_list = [score_df[score_df['level']==levels[level][0]].index.tolist() for level in range(num_levels)]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Tag levels"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Level 1: ['Billing Event']\n",
- "Level 2: ['Gender', 'Ad Type', 'Current Adsets', 'Device Platforms', 'Audience Strategy', 'Optimization Goal', 'AdsetStrategy', 'Campaign Objective']\n",
- "Level 3: ['Locations', 'strategy', 'Audience Types', 'Publisher Platforms', 'Facebook Positions']\n",
- "Level 4: ['Custom Audiences', 'Landing Pages', 'Lookalike Types', 'Interests', 'Age Range']\n"
- ]
- }
- ],
- "source": [
- "for level in range(num_levels):\n",
- " print('Level {0}:'.format(level + 1) , global_tag_list[level])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 27,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# global_tag_list = ['Campaign Objective']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "aggregations = {'fb_spend': pd.np.sum,\n",
- " 'ga_transactions': pd.np.sum,\n",
- " 'ga_revenue': pd.np.sum,\n",
- " }"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "overall = df_global['fb_spend'].sum() / df_global['ga_transactions'].sum()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df_global['ga_cpt'] = df_global['fb_spend'] / df_global['ga_transactions']\n",
- "df_global.replace([pd.np.inf, -pd.np.inf, float('inf')], 0, inplace=True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 31,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "overall_dev = df_global.ga_cpt.std()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 32,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "P = pd.np.percentile(df_global.fb_spend, [10, 100])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 33,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df_global_true = df_global.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 34,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df_global = df_global#[(df_global.fb_spend >= P[0]) & (df_global.fb_spend <= P[1])]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 35,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "df_global = df_global[df_global.ga_cpt > 0]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 96,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "def process_paths(df, tag_list_obj):\n",
- " \n",
- " \n",
- " def recurse_paths(tag_list, tag_list_old, tag_values_old):\n",
- " if len(tag_list):\n",
- " tag_level = tag_list.pop(0)\n",
- "\n",
- " tags = []\n",
- " if isinstance(tag_level, list):\n",
- " tags = tags + tag_level\n",
- " else:\n",
- " tags = tags + [tag_level]\n",
- " \n",
- " if len(tag_list_old):\n",
- " old = df.groupby(tag_list_old).agg(aggregations)\n",
- " old['ga_cpt'] = old['fb_spend'] / old['ga_transactions']\n",
- " old_cpt = old.loc[tag_values_old]['ga_cpt']\n",
- " old_spend = old.loc[tag_values_old]['fb_spend']\n",
- " else:\n",
- " old = df\n",
- " old_cpt = old.fb_spend.sum() / old.ga_transactions.sum()\n",
- " old_spend = old.fb_spend.sum()\n",
- "\n",
- " premature = True\n",
- " for tag in tags:\n",
- " new_tag_list = tag_list_old + [tag]\n",
- "\n",
- " new = df.groupby(new_tag_list).agg(aggregations)\n",
- " new['ga_cpt'] = new['fb_spend'] / new['ga_transactions']\n",
- " prop = new['fb_spend'] / old_spend\n",
- " \n",
- " if pd.np.max(prop) > 0.95:\n",
- " continue\n",
- " \n",
- " tag_values = set([val[-1] if isinstance(val, tuple) else val for val in new.index.values.tolist()] )\n",
- "\n",
- " if (tag_values == ['None']):\n",
- " continue\n",
- "\n",
- " for value in tag_values:\n",
- " if value == 'None':\n",
- " continue\n",
- " new_tag_value = tag_values_old + (value,)\n",
- " try:\n",
- " new.loc[new_tag_value]\n",
- " except:\n",
- " continue\n",
- " if True:#(new.loc[new_tag_value].fb_spend >= P[0]) & (new.loc[new_tag_value].fb_spend <= P[1]):\n",
- " value_df = new.loc[new_tag_value]\n",
- " new_cpt = value_df.fb_spend / value_df.ga_transactions\n",
- " new_spend = value_df.fb_spend\n",
- " \n",
- " bad_condition = ((new_cpt - old_cpt) / old_cpt ) > 0.1\n",
- " good_condition = ((new_cpt - old_cpt) / old_cpt )< -0.1\n",
- "# print(bad_condition, old_cpt, value_df.fb_spend / value_df.ga_transactions, new_tag_value)\n",
- " if bad_condition:\n",
- " bad[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
- " 'spend_prop': value_df.fb_spend*100 / df_global.fb_spend.sum(),\n",
- " 'imp_factor': abs((new_cpt - old_cpt)*(new_spend / old_spend)),\n",
- " 'tag_list': new_tag_list}\n",
- " \n",
- " if good_condition:\n",
- " good[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
- " 'spend_prop': value_df.fb_spend*100 / df_global.fb_spend.sum(),\n",
- " 'imp_factor': abs((new_cpt - old_cpt)*(new_spend / old_spend)),\n",
- " 'tag_list': new_tag_list} \n",
- " \n",
- " premature = False\n",
- " recurse_paths(tag_list[:], new_tag_list[:], new_tag_value[:])\n",
- " \n",
- " if premature and len(tag_list):\n",
- " recurse_paths(tag_list[:], tag_list_old, tag_values_old)\n",
- " \n",
- " recurse_paths(tag_list_obj, [], ())"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 97,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "bad = {}\n",
- "good = {}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 98,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "tag_list = global_tag_list\n",
- "process_paths(df_global, tag_list[:])\n",
- "bad_raw = bad.copy()\n",
- "good_raw = good.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 114,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "def get_filtered_paths(paths, rev=True):\n",
- " filtered_paths = {key: value for (key, value) in paths.items() if value['spend_prop'] > 1}\n",
- "\n",
- " processed_paths = {}\n",
- " for key, value in filtered_paths.items():\n",
- " l = list(key)\n",
- " none_list = ['-']*len(tag_list)\n",
- " none_list[:len(l)] = l\n",
- " if len(none_list) > 1:\n",
- " new_key = tuple(none_list)\n",
- " else:\n",
- " new_key = none_list[0]\n",
- "\n",
- " if tuple(value['tag_list']) in processed_paths:\n",
- " processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
- " else:\n",
- " processed_paths[tuple(value['tag_list'])] = {}\n",
- " processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
- "\n",
- " impact_values = {}\n",
- " for key, value in processed_paths.items():\n",
- " out_df = pd.DataFrame().from_dict(value, orient='index')\n",
- " impact = out_df.imp_factor.abs().max()\n",
- " impact_values[key] = impact\n",
- "\n",
- " impacts = sorted(impact_values.items(), key=operator.itemgetter(1), reverse=rev)\n",
- " \n",
- " return processed_paths, impacts"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Bad paths"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 115,
- "metadata": {
- "collapsed": false,
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Audience Types</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>Interests</th>\n",
- " <th>-</th>\n",
- " <td>17.832051</td>\n",
- " <td>316.352766</td>\n",
- " <td>1908.278364</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Device Platforms Audience Types - \n",
- "Impressions desktop or mobile Interests - 17.832051 316.352766 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Audience Types - \n",
- "Impressions desktop or mobile Interests - 1908.278364 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>AdsetStrategy</th>\n",
- " <th>Audience Types</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>visits</th>\n",
- " <th>Interests</th>\n",
- " <th>-</th>\n",
- " <td>11.344311</td>\n",
- " <td>303.444918</td>\n",
- " <td>1872.699811</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event AdsetStrategy Audience Types - \n",
- "Impressions visits Interests - 11.344311 303.444918 \n",
- "\n",
- " cpt \n",
- "Billing Event AdsetStrategy Audience Types - \n",
- "Impressions visits Interests - 1872.699811 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>Landing Pages</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Female</th>\n",
- " <th>feed</th>\n",
- " <th>www.koovs.com/women/brand/masaba-x-koovs</th>\n",
- " <td>1.243248</td>\n",
- " <td>276.168030</td>\n",
- " <td>4066.184375</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Link_clicks</th>\n",
- " <th>Female</th>\n",
- " <th>feed or right_hand_column</th>\n",
- " <th>www.koovs.com/women/dresses, www.koovs.com/women/tops/sortby-latest, www.koovs.com/women/shoes/sortby-latest, www.koovs.com/women/jeans/sortby-latest</th>\n",
- " <td>1.954581</td>\n",
- " <td>285.613044</td>\n",
- " <td>2764.402432</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Gender Facebook Positions Landing Pages \n",
- "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 1.243248 \n",
- "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 1.954581 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Gender Facebook Positions Landing Pages \n",
- "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 276.168030 \n",
- "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 285.613044 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Facebook Positions Landing Pages \n",
- "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 4066.184375 \n",
- "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 2764.402432 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Current Adsets</th>\n",
- " <th>Publisher Platforms</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Spend 2.5L</th>\n",
- " <th>audience_network or facebook</th>\n",
- " <th>-</th>\n",
- " <td>18.00953</td>\n",
- " <td>278.78765</td>\n",
- " <td>1529.927873</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Current Adsets Publisher Platforms - \n",
- "Impressions Spend 2.5L audience_network or facebook - 18.00953 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Current Adsets Publisher Platforms - \n",
- "Impressions Spend 2.5L audience_network or facebook - 278.78765 \n",
- "\n",
- " cpt \n",
- "Billing Event Current Adsets Publisher Platforms - \n",
- "Impressions Spend 2.5L audience_network or facebook - 1529.927873 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>AdsetStrategy</th>\n",
- " <th>Publisher Platforms</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>roas</th>\n",
- " <th>audience_network or facebook</th>\n",
- " <th>-</th>\n",
- " <td>18.00953</td>\n",
- " <td>278.78765</td>\n",
- " <td>1529.927873</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event AdsetStrategy Publisher Platforms - \n",
- "Impressions roas audience_network or facebook - 18.00953 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event AdsetStrategy Publisher Platforms - \n",
- "Impressions roas audience_network or facebook - 278.78765 \n",
- "\n",
- " cpt \n",
- "Billing Event AdsetStrategy Publisher Platforms - \n",
- "Impressions roas audience_network or facebook - 1529.927873 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>Age Range</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Female</th>\n",
- " <th>feed</th>\n",
- " <th>18-40</th>\n",
- " <td>1.243248</td>\n",
- " <td>276.16803</td>\n",
- " <td>4066.184375</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Gender Facebook Positions Age Range \n",
- "Impressions Female feed 18-40 1.243248 276.16803 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Facebook Positions Age Range \n",
- "Impressions Female feed 18-40 4066.184375 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Current Adsets</th>\n",
- " <th>strategy</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Spend 2.5L</th>\n",
- " <th>conversions</th>\n",
- " <th>-</th>\n",
- " <td>16.98156</td>\n",
- " <td>264.417576</td>\n",
- " <td>1532.141534</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Current Adsets strategy - \n",
- "Impressions Spend 2.5L conversions - 16.98156 264.417576 \n",
- "\n",
- " cpt \n",
- "Billing Event Current Adsets strategy - \n",
- "Impressions Spend 2.5L conversions - 1532.141534 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>AdsetStrategy</th>\n",
- " <th>strategy</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>roas</th>\n",
- " <th>conversions</th>\n",
- " <th>-</th>\n",
- " <td>16.98156</td>\n",
- " <td>264.417576</td>\n",
- " <td>1532.141534</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor cpt\n",
- "Billing Event AdsetStrategy strategy - \n",
- "Impressions roas conversions - 16.98156 264.417576 1532.141534"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Audience Types</th>\n",
- " <th>Landing Pages</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
- " <th>Interests</th>\n",
- " <th>www.koovs.com/women/brand/masaba-x-koovs</th>\n",
- " <td>1.649678</td>\n",
- " <td>245.149379</td>\n",
- " <td>4316.369000</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Lookalike</th>\n",
- " <th>www.koovs.com/women/dresses, www.koovs.com/women/tops/sortby-latest, www.koovs.com/women/shoes/sortby-latest, www.koovs.com/women/jeans/sortby-latest</th>\n",
- " <td>1.715253</td>\n",
- " <td>179.234914</td>\n",
- " <td>2087.416512</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Gender Audience Types Landing Pages \n",
- "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 1.649678 \n",
- " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 1.715253 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Gender Audience Types Landing Pages \n",
- "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 245.149379 \n",
- " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 179.234914 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Audience Types Landing Pages \n",
- "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 4316.369000 \n",
- " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 2087.416512 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Audience Types</th>\n",
- " <th>Age Range</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th>Female</th>\n",
- " <th>Interests</th>\n",
- " <th>18-40</th>\n",
- " <td>1.649678</td>\n",
- " <td>245.149379</td>\n",
- " <td>4316.369000</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Male</th>\n",
- " <th>Interests</th>\n",
- " <th>18-34</th>\n",
- " <td>1.039295</td>\n",
- " <td>228.524231</td>\n",
- " <td>4532.178333</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Gender Audience Types Age Range \n",
- "Impressions Female Interests 18-40 1.649678 245.149379 \n",
- " Male Interests 18-34 1.039295 228.524231 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Audience Types Age Range \n",
- "Impressions Female Interests 18-40 4316.369000 \n",
- " Male Interests 18-34 4532.178333 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Audience Types</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Female</th>\n",
- " <th>Interests</th>\n",
- " <th>-</th>\n",
- " <td>16.389444</td>\n",
- " <td>234.799858</td>\n",
- " <td>1880.82625</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor cpt\n",
- "Billing Event Gender Audience Types - \n",
- "Impressions Female Interests - 16.389444 234.799858 1880.82625"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Publisher Platforms</th>\n",
- " <th>Landing Pages</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Link_clicks</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>audience_network or facebook</th>\n",
- " <th>www.koovs.com/women/dresses, www.koovs.com/women/tops/sortby-latest, www.koovs.com/women/shoes/sortby-latest, www.koovs.com/women/jeans/sortby-latest</th>\n",
- " <td>1.954581</td>\n",
- " <td>230.161377</td>\n",
- " <td>2764.402432</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
- "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 1.954581 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
- "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 230.161377 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
- "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 2764.402432 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Audience Types</th>\n",
- " <th>Interests</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Male</th>\n",
- " <th>Interests</th>\n",
- " <th>Allen Solly or Amazon.com or Beauty or Coupons or Discounts and allowances or Others</th>\n",
- " <td>1.039295</td>\n",
- " <td>228.524231</td>\n",
- " <td>4532.178333</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Gender Audience Types Interests \n",
- "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 1.039295 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Gender Audience Types Interests \n",
- "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 228.524231 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Audience Types Interests \n",
- "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 4532.178333 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Publisher Platforms</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>audience_network or facebook</th>\n",
- " <th>-</th>\n",
- " <td>26.106853</td>\n",
- " <td>225.713802</td>\n",
- " <td>1597.856269</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Device Platforms Publisher Platforms - \n",
- "Impressions desktop or mobile audience_network or facebook - 26.106853 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Device Platforms Publisher Platforms - \n",
- "Impressions desktop or mobile audience_network or facebook - 225.713802 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Publisher Platforms - \n",
- "Impressions desktop or mobile audience_network or facebook - 1597.856269 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Audience Strategy</th>\n",
- " <th>Audience Types</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Prospecting</th>\n",
- " <th>Interests</th>\n",
- " <th>-</th>\n",
- " <td>28.146539</td>\n",
- " <td>210.452198</td>\n",
- " <td>1907.906062</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Audience Strategy Audience Types - \n",
- "Impressions Prospecting Interests - 28.146539 210.452198 \n",
- "\n",
- " cpt \n",
- "Billing Event Audience Strategy Audience Types - \n",
- "Impressions Prospecting Interests - 1907.906062 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "bad_new, bad_impacts = get_filtered_paths(bad_raw, True)\n",
- "bad_impacts_list = [value[0] for value in bad_impacts]\n",
- "for key in bad_impacts_list[0:15]:\n",
- " if key in list(bad_new.keys()):\n",
- " value = bad_new[key]\n",
- " b = pd.DataFrame().from_dict(value, orient='index')\n",
- " none_list = ['-']*len(tag_list)\n",
- " l = list(key)\n",
- " none_list[:len(l)] = l\n",
- "\n",
- " b.index = b.index.set_names(none_list)\n",
- " b = b[b['imp_factor'] > 0.7*b.imp_factor.max()]\n",
- " display(b)\n",
- " "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Good Paths"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 116,
- "metadata": {
- "collapsed": false,
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Locations</th>\n",
- " <th>Age Range</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>IN</th>\n",
- " <th>18-65</th>\n",
- " <td>11.585272</td>\n",
- " <td>164.974182</td>\n",
- " <td>838.527331</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Device Platforms Locations Age Range \n",
- "Impressions desktop or mobile IN 18-65 11.585272 164.974182 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Locations Age Range \n",
- "Impressions desktop or mobile IN 18-65 838.527331 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>AdsetStrategy</th>\n",
- " <th>Audience Types</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th>roas</th>\n",
- " <th>DPA</th>\n",
- " <th>-</th>\n",
- " <td>6.354514</td>\n",
- " <td>123.662525</td>\n",
- " <td>678.633878</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>visits</th>\n",
- " <th>Lookalike</th>\n",
- " <th>-</th>\n",
- " <td>4.040858</td>\n",
- " <td>146.426187</td>\n",
- " <td>903.664145</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event AdsetStrategy Audience Types - \n",
- "Impressions roas DPA - 6.354514 123.662525 \n",
- " visits Lookalike - 4.040858 146.426187 \n",
- "\n",
- " cpt \n",
- "Billing Event AdsetStrategy Audience Types - \n",
- "Impressions roas DPA - 678.633878 \n",
- " visits Lookalike - 903.664145 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>AdsetStrategy</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>-</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th>roas</th>\n",
- " <th>feed or right_hand_column</th>\n",
- " <th>-</th>\n",
- " <td>9.085970</td>\n",
- " <td>116.62279</td>\n",
- " <td>840.048092</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>visits</th>\n",
- " <th>feed</th>\n",
- " <th>-</th>\n",
- " <td>4.399702</td>\n",
- " <td>143.51486</td>\n",
- " <td>959.315125</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event AdsetStrategy Facebook Positions - \n",
- "Impressions roas feed or right_hand_column - 9.085970 \n",
- " visits feed - 4.399702 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event AdsetStrategy Facebook Positions - \n",
- "Impressions roas feed or right_hand_column - 116.62279 \n",
- " visits feed - 143.51486 \n",
- "\n",
- " cpt \n",
- "Billing Event AdsetStrategy Facebook Positions - \n",
- "Impressions roas feed or right_hand_column - 840.048092 \n",
- " visits feed - 959.315125 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>Age Range</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
- " <th>feed</th>\n",
- " <th>18-45</th>\n",
- " <td>9.794822</td>\n",
- " <td>107.971959</td>\n",
- " <td>1081.352996</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>feed or right_hand_column</th>\n",
- " <th>18-65</th>\n",
- " <td>3.595755</td>\n",
- " <td>141.969523</td>\n",
- " <td>1213.969355</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Gender Facebook Positions Age Range \n",
- "Impressions Female feed 18-45 9.794822 \n",
- " feed or right_hand_column 18-65 3.595755 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Gender Facebook Positions Age Range \n",
- "Impressions Female feed 18-45 107.971959 \n",
- " feed or right_hand_column 18-65 141.969523 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Facebook Positions Age Range \n",
- "Impressions Female feed 18-45 1081.352996 \n",
- " feed or right_hand_column 18-65 1213.969355 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Gender</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>Custom Audiences</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
- " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
- " <th>feed</th>\n",
- " <th>Lookalike (IN, 1%) - loyal_purchasers_data_20160415</th>\n",
- " <td>9.731727</td>\n",
- " <td>110.844955</td>\n",
- " <td>1076.658732</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>feed or right_hand_column</th>\n",
- " <th>ECOMMERCE MOBILE & EMAIL IDS FEB 2017</th>\n",
- " <td>3.595755</td>\n",
- " <td>141.969523</td>\n",
- " <td>1213.969355</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Gender Facebook Positions Custom Audiences \n",
- "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 9.731727 \n",
- " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 3.595755 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Gender Facebook Positions Custom Audiences \n",
- "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 110.844955 \n",
- " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 141.969523 \n",
- "\n",
- " cpt \n",
- "Billing Event Gender Facebook Positions Custom Audiences \n",
- "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 1076.658732 \n",
- " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 1213.969355 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Facebook Positions</th>\n",
- " <th>Landing Pages</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>feed or right_hand_column</th>\n",
- " <th>koovs.com</th>\n",
- " <td>6.354514</td>\n",
- " <td>136.237021</td>\n",
- " <td>678.633878</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Device Platforms Facebook Positions Landing Pages \n",
- "Impressions desktop or mobile feed or right_hand_column koovs.com 6.354514 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Device Platforms Facebook Positions Landing Pages \n",
- "Impressions desktop or mobile feed or right_hand_column koovs.com 136.237021 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Facebook Positions Landing Pages \n",
- "Impressions desktop or mobile feed or right_hand_column koovs.com 678.633878 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Ad Type</th>\n",
- " <th>strategy</th>\n",
- " <th>Lookalike Types</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Carousel</th>\n",
- " <th>conversions</th>\n",
- " <th>1%</th>\n",
- " <td>14.408359</td>\n",
- " <td>126.649392</td>\n",
- " <td>1176.266661</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop imp_factor \\\n",
- "Billing Event Ad Type strategy Lookalike Types \n",
- "Impressions Carousel conversions 1% 14.408359 126.649392 \n",
- "\n",
- " cpt \n",
- "Billing Event Ad Type strategy Lookalike Types \n",
- "Impressions Carousel conversions 1% 1176.266661 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Audience Strategy</th>\n",
- " <th>strategy</th>\n",
- " <th>Lookalike Types</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Prospecting</th>\n",
- " <th>conversions</th>\n",
- " <th>1%</th>\n",
- " <td>14.408359</td>\n",
- " <td>126.649392</td>\n",
- " <td>1176.266661</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Audience Strategy strategy Lookalike Types \n",
- "Impressions Prospecting conversions 1% 14.408359 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Audience Strategy strategy Lookalike Types \n",
- "Impressions Prospecting conversions 1% 126.649392 \n",
- "\n",
- " cpt \n",
- "Billing Event Audience Strategy strategy Lookalike Types \n",
- "Impressions Prospecting conversions 1% 1176.266661 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Campaign Objective</th>\n",
- " <th>strategy</th>\n",
- " <th>Lookalike Types</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>Conversions</th>\n",
- " <th>conversions</th>\n",
- " <th>1%</th>\n",
- " <td>14.408359</td>\n",
- " <td>126.649392</td>\n",
- " <td>1176.266661</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Campaign Objective strategy Lookalike Types \n",
- "Impressions Conversions conversions 1% 14.408359 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Campaign Objective strategy Lookalike Types \n",
- "Impressions Conversions conversions 1% 126.649392 \n",
- "\n",
- " cpt \n",
- "Billing Event Campaign Objective strategy Lookalike Types \n",
- "Impressions Conversions conversions 1% 1176.266661 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th>spend_prop</th>\n",
- " <th>imp_factor</th>\n",
- " <th>cpt</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>Billing Event</th>\n",
- " <th>Device Platforms</th>\n",
- " <th>Locations</th>\n",
- " <th>Landing Pages</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>Impressions</th>\n",
- " <th>desktop or mobile</th>\n",
- " <th>IN</th>\n",
- " <th>koovs.com</th>\n",
- " <td>6.354514</td>\n",
- " <td>125.464367</td>\n",
- " <td>678.633878</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " spend_prop \\\n",
- "Billing Event Device Platforms Locations Landing Pages \n",
- "Impressions desktop or mobile IN koovs.com 6.354514 \n",
- "\n",
- " imp_factor \\\n",
- "Billing Event Device Platforms Locations Landing Pages \n",
- "Impressions desktop or mobile IN koovs.com 125.464367 \n",
- "\n",
- " cpt \n",
- "Billing Event Device Platforms Locations Landing Pages \n",
- "Impressions desktop or mobile IN koovs.com 678.633878 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "good_new, good_impacts = get_filtered_paths(good_raw, True)\n",
- "good_impacts_list = [value[0] for value in good_impacts]\n",
- "for key in good_impacts_list[0:10]:\n",
- " if key in list(good_new.keys()):\n",
- " value = good_new[key]\n",
- " b = pd.DataFrame().from_dict(value, orient='index')\n",
- " none_list = ['-']*len(tag_list)\n",
- " l = list(key)\n",
- " none_list[:len(l)] = l\n",
- "\n",
- " b.index = b.index.set_names(none_list)\n",
- " b = b[b['imp_factor'] > 0.7*b.imp_factor.max()]\n",
- "\n",
- " display(b)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 117,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "strat_df = df.groupby(['Billing Event', 'Device Platforms', 'Audience Types']).sum()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 118,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "strat_df['prop'] = strat_df.fb_spend / df.fb_spend.sum()\n",
- "strat_df['cpt'] = strat_df.fb_spend / strat_df.ga_transactions"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "strat_df.iloc[strat_df.index.get_level_values('Audience Types') == 'Interests']"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "anaconda-cloud": {},
- "kernelspec": {
- "display_name": "Python [jarvis1]",
- "language": "python",
- "name": "Python [jarvis1]"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.5.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement