Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 74.22 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "collapsed": false
  8. },
  9. "outputs": [
  10. {
  11. "data": {
  12. "text/html": [
  13. "<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>"
  14. ]
  15. },
  16. "metadata": {},
  17. "output_type": "display_data"
  18. },
  19. {
  20. "data": {
  21. "text/html": [
  22. "<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>"
  23. ]
  24. },
  25. "metadata": {},
  26. "output_type": "display_data"
  27. }
  28. ],
  29. "source": [
  30. "import IPython.core.display as di\n",
  31. "\n",
  32. "# This line will hide code by default when the notebook is exported as HTML\n",
  33. "di.display_html('<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>', raw=True)\n",
  34. "\n",
  35. "# This line will add a button to toggle visibility of code blocks, for use with the HTML export version\n",
  36. "di.display_html('''<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>''', raw=True)"
  37. ]
  38. },
  39. {
  40. "cell_type": "code",
  41. "execution_count": 2,
  42. "metadata": {
  43. "collapsed": true
  44. },
  45. "outputs": [],
  46. "source": [
  47. "from IPython.display import display, HTML\n",
  48. "from itertools import combinations, product"
  49. ]
  50. },
  51. {
  52. "cell_type": "code",
  53. "execution_count": 3,
  54. "metadata": {
  55. "collapsed": false
  56. },
  57. "outputs": [],
  58. "source": [
  59. "from jarvis.brain.utility.data_preparation import (get_metrics_single_date, get_metrics_date_range)\n",
  60. "import numpy as np\n",
  61. "import pandas as pd\n",
  62. "from sklearn import tree\n",
  63. "import pydotplus\n",
  64. "global_metrics = ['ga_cpt', 'fb_spend', 'ga_transactions', 'ga_revenue']\n",
  65. "goal_metric = 'ga_cpt'"
  66. ]
  67. },
  68. {
  69. "cell_type": "code",
  70. "execution_count": 5,
  71. "metadata": {
  72. "collapsed": false
  73. },
  74. "outputs": [],
  75. "source": [
  76. "start = '2017-02-21'\n",
  77. "end = '2017-03-21'\n",
  78. "df = get_metrics_date_range(119, 'ad', start, end, global_metrics, custom_tags=True, active=False)"
  79. ]
  80. },
  81. {
  82. "cell_type": "code",
  83. "execution_count": 6,
  84. "metadata": {
  85. "collapsed": true
  86. },
  87. "outputs": [],
  88. "source": [
  89. "df_g = df"
  90. ]
  91. },
  92. {
  93. "cell_type": "code",
  94. "execution_count": 7,
  95. "metadata": {
  96. "collapsed": false
  97. },
  98. "outputs": [],
  99. "source": [
  100. "df= df[df['App Type'] == 'Web']"
  101. ]
  102. },
  103. {
  104. "cell_type": "code",
  105. "execution_count": 8,
  106. "metadata": {
  107. "collapsed": true
  108. },
  109. "outputs": [],
  110. "source": [
  111. "excluded_tags = ['Campaigns', 'ad_id', 'Image', 'Adsets', 'start_date', '_id', 'Ads',\n",
  112. " 'end_date', 'Active Ads Count in Adset', 'Active Adsets Count in Campaign', 'Labels', 'audience type', 'audience category', 'Product Set',\n",
  113. " 'Prominent Text', 'Dominant Color', 'DominantColor', 'ProminentText', 'NumberofFaces', 'Number of Faces', 'Sale', 'name', 'Carousel Count' , 'Ad Format']"
  114. ]
  115. },
  116. {
  117. "cell_type": "code",
  118. "execution_count": 9,
  119. "metadata": {
  120. "collapsed": true
  121. },
  122. "outputs": [],
  123. "source": [
  124. "def exclude_single_dominant_tag(tags, df):\n",
  125. " all_tags = []\n",
  126. " total_spend = df.fb_spend.sum()\n",
  127. " for tag in tags:\n",
  128. " grp = df.groupby(tag).sum()\n",
  129. " grp['prop'] = grp.fb_spend / total_spend\n",
  130. " if pd.np.max(grp['prop']) > 0.95:\n",
  131. " print(tag)\n",
  132. " continue\n",
  133. " all_tags.append(tag)\n",
  134. " return all_tags\n",
  135. "def clean_tags(df, excluded_tags, global_metrics):\n",
  136. " all_tags = list(set(df.columns) - set(global_metrics) - set(excluded_tags))\n",
  137. " all_tags = [tag for tag in all_tags if len(df[df[tag] != 'None'][tag].unique()) > 1]\n",
  138. " all_tags = [tag for tag in all_tags if df[tag].count() > 0.25*len(df)]\n",
  139. " all_tags = exclude_single_dominant_tag(all_tags, df) \n",
  140. " return all_tags"
  141. ]
  142. },
  143. {
  144. "cell_type": "code",
  145. "execution_count": 10,
  146. "metadata": {
  147. "collapsed": false
  148. },
  149. "outputs": [
  150. {
  151. "name": "stdout",
  152. "output_type": "stream",
  153. "text": [
  154. "Behaviors\n",
  155. "User OS\n"
  156. ]
  157. }
  158. ],
  159. "source": [
  160. "all_tags = clean_tags(df, excluded_tags, global_metrics)"
  161. ]
  162. },
  163. {
  164. "cell_type": "markdown",
  165. "metadata": {},
  166. "source": [
  167. "### Tags after cleanup"
  168. ]
  169. },
  170. {
  171. "cell_type": "code",
  172. "execution_count": 11,
  173. "metadata": {
  174. "collapsed": false
  175. },
  176. "outputs": [
  177. {
  178. "data": {
  179. "text/plain": [
  180. "['Audience Types',\n",
  181. " 'Gender',\n",
  182. " 'Device Platforms',\n",
  183. " 'Landing Pages',\n",
  184. " 'Lookalike Types',\n",
  185. " 'Facebook Positions',\n",
  186. " 'Audience Strategy',\n",
  187. " 'Interests',\n",
  188. " 'Custom Audiences',\n",
  189. " 'Ad Type',\n",
  190. " 'Locations',\n",
  191. " 'Optimization Goal',\n",
  192. " 'Campaign Objective',\n",
  193. " 'strategy',\n",
  194. " 'Age Range',\n",
  195. " 'Current Adsets',\n",
  196. " 'Billing Event',\n",
  197. " 'AdsetStrategy',\n",
  198. " 'Publisher Platforms']"
  199. ]
  200. },
  201. "execution_count": 11,
  202. "metadata": {},
  203. "output_type": "execute_result"
  204. }
  205. ],
  206. "source": [
  207. "all_tags"
  208. ]
  209. },
  210. {
  211. "cell_type": "code",
  212. "execution_count": 12,
  213. "metadata": {
  214. "collapsed": true
  215. },
  216. "outputs": [],
  217. "source": [
  218. "df_org = df.copy()"
  219. ]
  220. },
  221. {
  222. "cell_type": "code",
  223. "execution_count": 13,
  224. "metadata": {
  225. "collapsed": false
  226. },
  227. "outputs": [],
  228. "source": [
  229. "df = df_org[df_org['App Type'] == 'Web']"
  230. ]
  231. },
  232. {
  233. "cell_type": "code",
  234. "execution_count": 14,
  235. "metadata": {
  236. "collapsed": false
  237. },
  238. "outputs": [],
  239. "source": [
  240. "overall_cpt = df.fb_spend.sum() / df.ga_transactions.sum()"
  241. ]
  242. },
  243. {
  244. "cell_type": "code",
  245. "execution_count": 15,
  246. "metadata": {
  247. "collapsed": true
  248. },
  249. "outputs": [],
  250. "source": [
  251. "df_global = df.copy()"
  252. ]
  253. },
  254. {
  255. "cell_type": "code",
  256. "execution_count": 16,
  257. "metadata": {
  258. "collapsed": false
  259. },
  260. "outputs": [],
  261. "source": [
  262. "total_spend = df_global.fb_spend.sum()"
  263. ]
  264. },
  265. {
  266. "cell_type": "code",
  267. "execution_count": 17,
  268. "metadata": {
  269. "collapsed": false
  270. },
  271. "outputs": [],
  272. "source": [
  273. "tag_scores = {}\n",
  274. "for tag in all_tags:\n",
  275. " temp = df.groupby([tag]).sum()\n",
  276. " temp['prop'] = temp['fb_spend'] / total_spend\n",
  277. " tag_scores[tag] = temp[temp.index != 'None']['prop'].mean()"
  278. ]
  279. },
  280. {
  281. "cell_type": "markdown",
  282. "metadata": {},
  283. "source": [
  284. "### Scores"
  285. ]
  286. },
  287. {
  288. "cell_type": "code",
  289. "execution_count": 18,
  290. "metadata": {
  291. "collapsed": false
  292. },
  293. "outputs": [
  294. {
  295. "data": {
  296. "text/plain": [
  297. "[('Interests', 0.012374212466183187),\n",
  298. " ('Landing Pages', 0.016936776591743516),\n",
  299. " ('Custom Audiences', 0.025144310123355166),\n",
  300. " ('Lookalike Types', 0.0362420481952802),\n",
  301. " ('Age Range', 0.07142857142857138),\n",
  302. " ('Audience Types', 0.12491133392877618),\n",
  303. " ('strategy', 0.1595410051068123),\n",
  304. " ('Facebook Positions', 0.16368058291676418),\n",
  305. " ('Locations', 0.16666666666666674),\n",
  306. " ('Publisher Platforms', 0.2),\n",
  307. " ('Optimization Goal', 0.24999999999999992),\n",
  308. " ('Campaign Objective', 0.24999999999999997),\n",
  309. " ('Current Adsets', 0.26607416518977656),\n",
  310. " ('AdsetStrategy', 0.3059956515591048),\n",
  311. " ('Audience Strategy', 0.3333333333333332),\n",
  312. " ('Gender', 0.33333333333333326),\n",
  313. " ('Device Platforms', 0.3333333333333334),\n",
  314. " ('Ad Type', 0.33333333333333387),\n",
  315. " ('Billing Event', 0.4999999999999998)]"
  316. ]
  317. },
  318. "execution_count": 18,
  319. "metadata": {},
  320. "output_type": "execute_result"
  321. }
  322. ],
  323. "source": [
  324. "import operator\n",
  325. "sorted(tag_scores.items(), key=operator.itemgetter(1))"
  326. ]
  327. },
  328. {
  329. "cell_type": "code",
  330. "execution_count": 19,
  331. "metadata": {
  332. "collapsed": false
  333. },
  334. "outputs": [],
  335. "source": [
  336. "score_df = pd.DataFrame().from_dict(tag_scores, orient='index')\n",
  337. "score_df = score_df.rename(columns = {0:'score'})"
  338. ]
  339. },
  340. {
  341. "cell_type": "code",
  342. "execution_count": 20,
  343. "metadata": {
  344. "collapsed": true
  345. },
  346. "outputs": [],
  347. "source": [
  348. "score_df = score_df[pd.notnull(score_df['score'])]"
  349. ]
  350. },
  351. {
  352. "cell_type": "code",
  353. "execution_count": 21,
  354. "metadata": {
  355. "collapsed": true
  356. },
  357. "outputs": [],
  358. "source": [
  359. "num_levels = 4"
  360. ]
  361. },
  362. {
  363. "cell_type": "code",
  364. "execution_count": 22,
  365. "metadata": {
  366. "collapsed": false
  367. },
  368. "outputs": [],
  369. "source": [
  370. "from sklearn.cluster import KMeans\n",
  371. "from sklearn import preprocessing\n",
  372. "\n",
  373. "train = score_df[pd.notnull(score_df['score'])].values\n",
  374. "train = preprocessing.scale(train)\n",
  375. "kmeans_model = KMeans(n_clusters=num_levels, random_state=1).fit(train)"
  376. ]
  377. },
  378. {
  379. "cell_type": "code",
  380. "execution_count": 23,
  381. "metadata": {
  382. "collapsed": false
  383. },
  384. "outputs": [],
  385. "source": [
  386. "score_df['level'] = kmeans_model.labels_"
  387. ]
  388. },
  389. {
  390. "cell_type": "code",
  391. "execution_count": 24,
  392. "metadata": {
  393. "collapsed": false
  394. },
  395. "outputs": [],
  396. "source": [
  397. "score_levels = {}\n",
  398. "for level in range(num_levels):\n",
  399. " score_levels[level] = score_df[score_df['level'] == level]['score'].mean()\n",
  400. "\n",
  401. "levels = sorted(score_levels.items(), key=operator.itemgetter(1), reverse=True)"
  402. ]
  403. },
  404. {
  405. "cell_type": "code",
  406. "execution_count": 25,
  407. "metadata": {
  408. "collapsed": false
  409. },
  410. "outputs": [],
  411. "source": [
  412. "global_tag_list = [score_df[score_df['level']==levels[level][0]].index.tolist() for level in range(num_levels)]"
  413. ]
  414. },
  415. {
  416. "cell_type": "markdown",
  417. "metadata": {},
  418. "source": [
  419. "### Tag levels"
  420. ]
  421. },
  422. {
  423. "cell_type": "code",
  424. "execution_count": 26,
  425. "metadata": {
  426. "collapsed": false
  427. },
  428. "outputs": [
  429. {
  430. "name": "stdout",
  431. "output_type": "stream",
  432. "text": [
  433. "Level 1: ['Billing Event']\n",
  434. "Level 2: ['Gender', 'Ad Type', 'Current Adsets', 'Device Platforms', 'Audience Strategy', 'Optimization Goal', 'AdsetStrategy', 'Campaign Objective']\n",
  435. "Level 3: ['Locations', 'strategy', 'Audience Types', 'Publisher Platforms', 'Facebook Positions']\n",
  436. "Level 4: ['Custom Audiences', 'Landing Pages', 'Lookalike Types', 'Interests', 'Age Range']\n"
  437. ]
  438. }
  439. ],
  440. "source": [
  441. "for level in range(num_levels):\n",
  442. " print('Level {0}:'.format(level + 1) , global_tag_list[level])"
  443. ]
  444. },
  445. {
  446. "cell_type": "code",
  447. "execution_count": 27,
  448. "metadata": {
  449. "collapsed": true
  450. },
  451. "outputs": [],
  452. "source": [
  453. "# global_tag_list = ['Campaign Objective']"
  454. ]
  455. },
  456. {
  457. "cell_type": "code",
  458. "execution_count": 28,
  459. "metadata": {
  460. "collapsed": true
  461. },
  462. "outputs": [],
  463. "source": [
  464. "aggregations = {'fb_spend': pd.np.sum,\n",
  465. " 'ga_transactions': pd.np.sum,\n",
  466. " 'ga_revenue': pd.np.sum,\n",
  467. " }"
  468. ]
  469. },
  470. {
  471. "cell_type": "code",
  472. "execution_count": 29,
  473. "metadata": {
  474. "collapsed": false
  475. },
  476. "outputs": [],
  477. "source": [
  478. "overall = df_global['fb_spend'].sum() / df_global['ga_transactions'].sum()"
  479. ]
  480. },
  481. {
  482. "cell_type": "code",
  483. "execution_count": 30,
  484. "metadata": {
  485. "collapsed": false
  486. },
  487. "outputs": [],
  488. "source": [
  489. "df_global['ga_cpt'] = df_global['fb_spend'] / df_global['ga_transactions']\n",
  490. "df_global.replace([pd.np.inf, -pd.np.inf, float('inf')], 0, inplace=True)"
  491. ]
  492. },
  493. {
  494. "cell_type": "code",
  495. "execution_count": 31,
  496. "metadata": {
  497. "collapsed": true
  498. },
  499. "outputs": [],
  500. "source": [
  501. "overall_dev = df_global.ga_cpt.std()"
  502. ]
  503. },
  504. {
  505. "cell_type": "code",
  506. "execution_count": 32,
  507. "metadata": {
  508. "collapsed": false
  509. },
  510. "outputs": [],
  511. "source": [
  512. "P = pd.np.percentile(df_global.fb_spend, [10, 100])"
  513. ]
  514. },
  515. {
  516. "cell_type": "code",
  517. "execution_count": 33,
  518. "metadata": {
  519. "collapsed": false
  520. },
  521. "outputs": [],
  522. "source": [
  523. "df_global_true = df_global.copy()"
  524. ]
  525. },
  526. {
  527. "cell_type": "code",
  528. "execution_count": 34,
  529. "metadata": {
  530. "collapsed": true
  531. },
  532. "outputs": [],
  533. "source": [
  534. "df_global = df_global#[(df_global.fb_spend >= P[0]) & (df_global.fb_spend <= P[1])]"
  535. ]
  536. },
  537. {
  538. "cell_type": "code",
  539. "execution_count": 35,
  540. "metadata": {
  541. "collapsed": true
  542. },
  543. "outputs": [],
  544. "source": [
  545. "df_global = df_global[df_global.ga_cpt > 0]"
  546. ]
  547. },
  548. {
  549. "cell_type": "code",
  550. "execution_count": 96,
  551. "metadata": {
  552. "collapsed": false
  553. },
  554. "outputs": [],
  555. "source": [
  556. "def process_paths(df, tag_list_obj):\n",
  557. " \n",
  558. " \n",
  559. " def recurse_paths(tag_list, tag_list_old, tag_values_old):\n",
  560. " if len(tag_list):\n",
  561. " tag_level = tag_list.pop(0)\n",
  562. "\n",
  563. " tags = []\n",
  564. " if isinstance(tag_level, list):\n",
  565. " tags = tags + tag_level\n",
  566. " else:\n",
  567. " tags = tags + [tag_level]\n",
  568. " \n",
  569. " if len(tag_list_old):\n",
  570. " old = df.groupby(tag_list_old).agg(aggregations)\n",
  571. " old['ga_cpt'] = old['fb_spend'] / old['ga_transactions']\n",
  572. " old_cpt = old.loc[tag_values_old]['ga_cpt']\n",
  573. " old_spend = old.loc[tag_values_old]['fb_spend']\n",
  574. " else:\n",
  575. " old = df\n",
  576. " old_cpt = old.fb_spend.sum() / old.ga_transactions.sum()\n",
  577. " old_spend = old.fb_spend.sum()\n",
  578. "\n",
  579. " premature = True\n",
  580. " for tag in tags:\n",
  581. " new_tag_list = tag_list_old + [tag]\n",
  582. "\n",
  583. " new = df.groupby(new_tag_list).agg(aggregations)\n",
  584. " new['ga_cpt'] = new['fb_spend'] / new['ga_transactions']\n",
  585. " prop = new['fb_spend'] / old_spend\n",
  586. " \n",
  587. " if pd.np.max(prop) > 0.95:\n",
  588. " continue\n",
  589. " \n",
  590. " tag_values = set([val[-1] if isinstance(val, tuple) else val for val in new.index.values.tolist()] )\n",
  591. "\n",
  592. " if (tag_values == ['None']):\n",
  593. " continue\n",
  594. "\n",
  595. " for value in tag_values:\n",
  596. " if value == 'None':\n",
  597. " continue\n",
  598. " new_tag_value = tag_values_old + (value,)\n",
  599. " try:\n",
  600. " new.loc[new_tag_value]\n",
  601. " except:\n",
  602. " continue\n",
  603. " if True:#(new.loc[new_tag_value].fb_spend >= P[0]) & (new.loc[new_tag_value].fb_spend <= P[1]):\n",
  604. " value_df = new.loc[new_tag_value]\n",
  605. " new_cpt = value_df.fb_spend / value_df.ga_transactions\n",
  606. " new_spend = value_df.fb_spend\n",
  607. " \n",
  608. " bad_condition = ((new_cpt - old_cpt) / old_cpt ) > 0.1\n",
  609. " good_condition = ((new_cpt - old_cpt) / old_cpt )< -0.1\n",
  610. "# print(bad_condition, old_cpt, value_df.fb_spend / value_df.ga_transactions, new_tag_value)\n",
  611. " if bad_condition:\n",
  612. " bad[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
  613. " 'spend_prop': value_df.fb_spend*100 / df_global.fb_spend.sum(),\n",
  614. " 'imp_factor': abs((new_cpt - old_cpt)*(new_spend / old_spend)),\n",
  615. " 'tag_list': new_tag_list}\n",
  616. " \n",
  617. " if good_condition:\n",
  618. " good[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
  619. " 'spend_prop': value_df.fb_spend*100 / df_global.fb_spend.sum(),\n",
  620. " 'imp_factor': abs((new_cpt - old_cpt)*(new_spend / old_spend)),\n",
  621. " 'tag_list': new_tag_list} \n",
  622. " \n",
  623. " premature = False\n",
  624. " recurse_paths(tag_list[:], new_tag_list[:], new_tag_value[:])\n",
  625. " \n",
  626. " if premature and len(tag_list):\n",
  627. " recurse_paths(tag_list[:], tag_list_old, tag_values_old)\n",
  628. " \n",
  629. " recurse_paths(tag_list_obj, [], ())"
  630. ]
  631. },
  632. {
  633. "cell_type": "code",
  634. "execution_count": 97,
  635. "metadata": {
  636. "collapsed": true
  637. },
  638. "outputs": [],
  639. "source": [
  640. "bad = {}\n",
  641. "good = {}"
  642. ]
  643. },
  644. {
  645. "cell_type": "code",
  646. "execution_count": 98,
  647. "metadata": {
  648. "collapsed": false
  649. },
  650. "outputs": [],
  651. "source": [
  652. "tag_list = global_tag_list\n",
  653. "process_paths(df_global, tag_list[:])\n",
  654. "bad_raw = bad.copy()\n",
  655. "good_raw = good.copy()"
  656. ]
  657. },
  658. {
  659. "cell_type": "code",
  660. "execution_count": 114,
  661. "metadata": {
  662. "collapsed": false
  663. },
  664. "outputs": [],
  665. "source": [
  666. "def get_filtered_paths(paths, rev=True):\n",
  667. " filtered_paths = {key: value for (key, value) in paths.items() if value['spend_prop'] > 1}\n",
  668. "\n",
  669. " processed_paths = {}\n",
  670. " for key, value in filtered_paths.items():\n",
  671. " l = list(key)\n",
  672. " none_list = ['-']*len(tag_list)\n",
  673. " none_list[:len(l)] = l\n",
  674. " if len(none_list) > 1:\n",
  675. " new_key = tuple(none_list)\n",
  676. " else:\n",
  677. " new_key = none_list[0]\n",
  678. "\n",
  679. " if tuple(value['tag_list']) in processed_paths:\n",
  680. " processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
  681. " else:\n",
  682. " processed_paths[tuple(value['tag_list'])] = {}\n",
  683. " processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
  684. "\n",
  685. " impact_values = {}\n",
  686. " for key, value in processed_paths.items():\n",
  687. " out_df = pd.DataFrame().from_dict(value, orient='index')\n",
  688. " impact = out_df.imp_factor.abs().max()\n",
  689. " impact_values[key] = impact\n",
  690. "\n",
  691. " impacts = sorted(impact_values.items(), key=operator.itemgetter(1), reverse=rev)\n",
  692. " \n",
  693. " return processed_paths, impacts"
  694. ]
  695. },
  696. {
  697. "cell_type": "markdown",
  698. "metadata": {},
  699. "source": [
  700. "### Bad paths"
  701. ]
  702. },
  703. {
  704. "cell_type": "code",
  705. "execution_count": 115,
  706. "metadata": {
  707. "collapsed": false,
  708. "scrolled": false
  709. },
  710. "outputs": [
  711. {
  712. "data": {
  713. "text/html": [
  714. "<div>\n",
  715. "<table border=\"1\" class=\"dataframe\">\n",
  716. " <thead>\n",
  717. " <tr style=\"text-align: right;\">\n",
  718. " <th></th>\n",
  719. " <th></th>\n",
  720. " <th></th>\n",
  721. " <th></th>\n",
  722. " <th>spend_prop</th>\n",
  723. " <th>imp_factor</th>\n",
  724. " <th>cpt</th>\n",
  725. " </tr>\n",
  726. " <tr>\n",
  727. " <th>Billing Event</th>\n",
  728. " <th>Device Platforms</th>\n",
  729. " <th>Audience Types</th>\n",
  730. " <th>-</th>\n",
  731. " <th></th>\n",
  732. " <th></th>\n",
  733. " <th></th>\n",
  734. " </tr>\n",
  735. " </thead>\n",
  736. " <tbody>\n",
  737. " <tr>\n",
  738. " <th>Impressions</th>\n",
  739. " <th>desktop or mobile</th>\n",
  740. " <th>Interests</th>\n",
  741. " <th>-</th>\n",
  742. " <td>17.832051</td>\n",
  743. " <td>316.352766</td>\n",
  744. " <td>1908.278364</td>\n",
  745. " </tr>\n",
  746. " </tbody>\n",
  747. "</table>\n",
  748. "</div>"
  749. ],
  750. "text/plain": [
  751. " spend_prop imp_factor \\\n",
  752. "Billing Event Device Platforms Audience Types - \n",
  753. "Impressions desktop or mobile Interests - 17.832051 316.352766 \n",
  754. "\n",
  755. " cpt \n",
  756. "Billing Event Device Platforms Audience Types - \n",
  757. "Impressions desktop or mobile Interests - 1908.278364 "
  758. ]
  759. },
  760. "metadata": {},
  761. "output_type": "display_data"
  762. },
  763. {
  764. "data": {
  765. "text/html": [
  766. "<div>\n",
  767. "<table border=\"1\" class=\"dataframe\">\n",
  768. " <thead>\n",
  769. " <tr style=\"text-align: right;\">\n",
  770. " <th></th>\n",
  771. " <th></th>\n",
  772. " <th></th>\n",
  773. " <th></th>\n",
  774. " <th>spend_prop</th>\n",
  775. " <th>imp_factor</th>\n",
  776. " <th>cpt</th>\n",
  777. " </tr>\n",
  778. " <tr>\n",
  779. " <th>Billing Event</th>\n",
  780. " <th>AdsetStrategy</th>\n",
  781. " <th>Audience Types</th>\n",
  782. " <th>-</th>\n",
  783. " <th></th>\n",
  784. " <th></th>\n",
  785. " <th></th>\n",
  786. " </tr>\n",
  787. " </thead>\n",
  788. " <tbody>\n",
  789. " <tr>\n",
  790. " <th>Impressions</th>\n",
  791. " <th>visits</th>\n",
  792. " <th>Interests</th>\n",
  793. " <th>-</th>\n",
  794. " <td>11.344311</td>\n",
  795. " <td>303.444918</td>\n",
  796. " <td>1872.699811</td>\n",
  797. " </tr>\n",
  798. " </tbody>\n",
  799. "</table>\n",
  800. "</div>"
  801. ],
  802. "text/plain": [
  803. " spend_prop imp_factor \\\n",
  804. "Billing Event AdsetStrategy Audience Types - \n",
  805. "Impressions visits Interests - 11.344311 303.444918 \n",
  806. "\n",
  807. " cpt \n",
  808. "Billing Event AdsetStrategy Audience Types - \n",
  809. "Impressions visits Interests - 1872.699811 "
  810. ]
  811. },
  812. "metadata": {},
  813. "output_type": "display_data"
  814. },
  815. {
  816. "data": {
  817. "text/html": [
  818. "<div>\n",
  819. "<table border=\"1\" class=\"dataframe\">\n",
  820. " <thead>\n",
  821. " <tr style=\"text-align: right;\">\n",
  822. " <th></th>\n",
  823. " <th></th>\n",
  824. " <th></th>\n",
  825. " <th></th>\n",
  826. " <th>spend_prop</th>\n",
  827. " <th>imp_factor</th>\n",
  828. " <th>cpt</th>\n",
  829. " </tr>\n",
  830. " <tr>\n",
  831. " <th>Billing Event</th>\n",
  832. " <th>Gender</th>\n",
  833. " <th>Facebook Positions</th>\n",
  834. " <th>Landing Pages</th>\n",
  835. " <th></th>\n",
  836. " <th></th>\n",
  837. " <th></th>\n",
  838. " </tr>\n",
  839. " </thead>\n",
  840. " <tbody>\n",
  841. " <tr>\n",
  842. " <th>Impressions</th>\n",
  843. " <th>Female</th>\n",
  844. " <th>feed</th>\n",
  845. " <th>www.koovs.com/women/brand/masaba-x-koovs</th>\n",
  846. " <td>1.243248</td>\n",
  847. " <td>276.168030</td>\n",
  848. " <td>4066.184375</td>\n",
  849. " </tr>\n",
  850. " <tr>\n",
  851. " <th>Link_clicks</th>\n",
  852. " <th>Female</th>\n",
  853. " <th>feed or right_hand_column</th>\n",
  854. " <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",
  855. " <td>1.954581</td>\n",
  856. " <td>285.613044</td>\n",
  857. " <td>2764.402432</td>\n",
  858. " </tr>\n",
  859. " </tbody>\n",
  860. "</table>\n",
  861. "</div>"
  862. ],
  863. "text/plain": [
  864. " spend_prop \\\n",
  865. "Billing Event Gender Facebook Positions Landing Pages \n",
  866. "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 1.243248 \n",
  867. "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 1.954581 \n",
  868. "\n",
  869. " imp_factor \\\n",
  870. "Billing Event Gender Facebook Positions Landing Pages \n",
  871. "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 276.168030 \n",
  872. "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 285.613044 \n",
  873. "\n",
  874. " cpt \n",
  875. "Billing Event Gender Facebook Positions Landing Pages \n",
  876. "Impressions Female feed www.koovs.com/women/brand/masaba-x-koovs 4066.184375 \n",
  877. "Link_clicks Female feed or right_hand_column www.koovs.com/women/dresses, www.koovs.com/wome... 2764.402432 "
  878. ]
  879. },
  880. "metadata": {},
  881. "output_type": "display_data"
  882. },
  883. {
  884. "data": {
  885. "text/html": [
  886. "<div>\n",
  887. "<table border=\"1\" class=\"dataframe\">\n",
  888. " <thead>\n",
  889. " <tr style=\"text-align: right;\">\n",
  890. " <th></th>\n",
  891. " <th></th>\n",
  892. " <th></th>\n",
  893. " <th></th>\n",
  894. " <th>spend_prop</th>\n",
  895. " <th>imp_factor</th>\n",
  896. " <th>cpt</th>\n",
  897. " </tr>\n",
  898. " <tr>\n",
  899. " <th>Billing Event</th>\n",
  900. " <th>Current Adsets</th>\n",
  901. " <th>Publisher Platforms</th>\n",
  902. " <th>-</th>\n",
  903. " <th></th>\n",
  904. " <th></th>\n",
  905. " <th></th>\n",
  906. " </tr>\n",
  907. " </thead>\n",
  908. " <tbody>\n",
  909. " <tr>\n",
  910. " <th>Impressions</th>\n",
  911. " <th>Spend 2.5L</th>\n",
  912. " <th>audience_network or facebook</th>\n",
  913. " <th>-</th>\n",
  914. " <td>18.00953</td>\n",
  915. " <td>278.78765</td>\n",
  916. " <td>1529.927873</td>\n",
  917. " </tr>\n",
  918. " </tbody>\n",
  919. "</table>\n",
  920. "</div>"
  921. ],
  922. "text/plain": [
  923. " spend_prop \\\n",
  924. "Billing Event Current Adsets Publisher Platforms - \n",
  925. "Impressions Spend 2.5L audience_network or facebook - 18.00953 \n",
  926. "\n",
  927. " imp_factor \\\n",
  928. "Billing Event Current Adsets Publisher Platforms - \n",
  929. "Impressions Spend 2.5L audience_network or facebook - 278.78765 \n",
  930. "\n",
  931. " cpt \n",
  932. "Billing Event Current Adsets Publisher Platforms - \n",
  933. "Impressions Spend 2.5L audience_network or facebook - 1529.927873 "
  934. ]
  935. },
  936. "metadata": {},
  937. "output_type": "display_data"
  938. },
  939. {
  940. "data": {
  941. "text/html": [
  942. "<div>\n",
  943. "<table border=\"1\" class=\"dataframe\">\n",
  944. " <thead>\n",
  945. " <tr style=\"text-align: right;\">\n",
  946. " <th></th>\n",
  947. " <th></th>\n",
  948. " <th></th>\n",
  949. " <th></th>\n",
  950. " <th>spend_prop</th>\n",
  951. " <th>imp_factor</th>\n",
  952. " <th>cpt</th>\n",
  953. " </tr>\n",
  954. " <tr>\n",
  955. " <th>Billing Event</th>\n",
  956. " <th>AdsetStrategy</th>\n",
  957. " <th>Publisher Platforms</th>\n",
  958. " <th>-</th>\n",
  959. " <th></th>\n",
  960. " <th></th>\n",
  961. " <th></th>\n",
  962. " </tr>\n",
  963. " </thead>\n",
  964. " <tbody>\n",
  965. " <tr>\n",
  966. " <th>Impressions</th>\n",
  967. " <th>roas</th>\n",
  968. " <th>audience_network or facebook</th>\n",
  969. " <th>-</th>\n",
  970. " <td>18.00953</td>\n",
  971. " <td>278.78765</td>\n",
  972. " <td>1529.927873</td>\n",
  973. " </tr>\n",
  974. " </tbody>\n",
  975. "</table>\n",
  976. "</div>"
  977. ],
  978. "text/plain": [
  979. " spend_prop \\\n",
  980. "Billing Event AdsetStrategy Publisher Platforms - \n",
  981. "Impressions roas audience_network or facebook - 18.00953 \n",
  982. "\n",
  983. " imp_factor \\\n",
  984. "Billing Event AdsetStrategy Publisher Platforms - \n",
  985. "Impressions roas audience_network or facebook - 278.78765 \n",
  986. "\n",
  987. " cpt \n",
  988. "Billing Event AdsetStrategy Publisher Platforms - \n",
  989. "Impressions roas audience_network or facebook - 1529.927873 "
  990. ]
  991. },
  992. "metadata": {},
  993. "output_type": "display_data"
  994. },
  995. {
  996. "data": {
  997. "text/html": [
  998. "<div>\n",
  999. "<table border=\"1\" class=\"dataframe\">\n",
  1000. " <thead>\n",
  1001. " <tr style=\"text-align: right;\">\n",
  1002. " <th></th>\n",
  1003. " <th></th>\n",
  1004. " <th></th>\n",
  1005. " <th></th>\n",
  1006. " <th>spend_prop</th>\n",
  1007. " <th>imp_factor</th>\n",
  1008. " <th>cpt</th>\n",
  1009. " </tr>\n",
  1010. " <tr>\n",
  1011. " <th>Billing Event</th>\n",
  1012. " <th>Gender</th>\n",
  1013. " <th>Facebook Positions</th>\n",
  1014. " <th>Age Range</th>\n",
  1015. " <th></th>\n",
  1016. " <th></th>\n",
  1017. " <th></th>\n",
  1018. " </tr>\n",
  1019. " </thead>\n",
  1020. " <tbody>\n",
  1021. " <tr>\n",
  1022. " <th>Impressions</th>\n",
  1023. " <th>Female</th>\n",
  1024. " <th>feed</th>\n",
  1025. " <th>18-40</th>\n",
  1026. " <td>1.243248</td>\n",
  1027. " <td>276.16803</td>\n",
  1028. " <td>4066.184375</td>\n",
  1029. " </tr>\n",
  1030. " </tbody>\n",
  1031. "</table>\n",
  1032. "</div>"
  1033. ],
  1034. "text/plain": [
  1035. " spend_prop imp_factor \\\n",
  1036. "Billing Event Gender Facebook Positions Age Range \n",
  1037. "Impressions Female feed 18-40 1.243248 276.16803 \n",
  1038. "\n",
  1039. " cpt \n",
  1040. "Billing Event Gender Facebook Positions Age Range \n",
  1041. "Impressions Female feed 18-40 4066.184375 "
  1042. ]
  1043. },
  1044. "metadata": {},
  1045. "output_type": "display_data"
  1046. },
  1047. {
  1048. "data": {
  1049. "text/html": [
  1050. "<div>\n",
  1051. "<table border=\"1\" class=\"dataframe\">\n",
  1052. " <thead>\n",
  1053. " <tr style=\"text-align: right;\">\n",
  1054. " <th></th>\n",
  1055. " <th></th>\n",
  1056. " <th></th>\n",
  1057. " <th></th>\n",
  1058. " <th>spend_prop</th>\n",
  1059. " <th>imp_factor</th>\n",
  1060. " <th>cpt</th>\n",
  1061. " </tr>\n",
  1062. " <tr>\n",
  1063. " <th>Billing Event</th>\n",
  1064. " <th>Current Adsets</th>\n",
  1065. " <th>strategy</th>\n",
  1066. " <th>-</th>\n",
  1067. " <th></th>\n",
  1068. " <th></th>\n",
  1069. " <th></th>\n",
  1070. " </tr>\n",
  1071. " </thead>\n",
  1072. " <tbody>\n",
  1073. " <tr>\n",
  1074. " <th>Impressions</th>\n",
  1075. " <th>Spend 2.5L</th>\n",
  1076. " <th>conversions</th>\n",
  1077. " <th>-</th>\n",
  1078. " <td>16.98156</td>\n",
  1079. " <td>264.417576</td>\n",
  1080. " <td>1532.141534</td>\n",
  1081. " </tr>\n",
  1082. " </tbody>\n",
  1083. "</table>\n",
  1084. "</div>"
  1085. ],
  1086. "text/plain": [
  1087. " spend_prop imp_factor \\\n",
  1088. "Billing Event Current Adsets strategy - \n",
  1089. "Impressions Spend 2.5L conversions - 16.98156 264.417576 \n",
  1090. "\n",
  1091. " cpt \n",
  1092. "Billing Event Current Adsets strategy - \n",
  1093. "Impressions Spend 2.5L conversions - 1532.141534 "
  1094. ]
  1095. },
  1096. "metadata": {},
  1097. "output_type": "display_data"
  1098. },
  1099. {
  1100. "data": {
  1101. "text/html": [
  1102. "<div>\n",
  1103. "<table border=\"1\" class=\"dataframe\">\n",
  1104. " <thead>\n",
  1105. " <tr style=\"text-align: right;\">\n",
  1106. " <th></th>\n",
  1107. " <th></th>\n",
  1108. " <th></th>\n",
  1109. " <th></th>\n",
  1110. " <th>spend_prop</th>\n",
  1111. " <th>imp_factor</th>\n",
  1112. " <th>cpt</th>\n",
  1113. " </tr>\n",
  1114. " <tr>\n",
  1115. " <th>Billing Event</th>\n",
  1116. " <th>AdsetStrategy</th>\n",
  1117. " <th>strategy</th>\n",
  1118. " <th>-</th>\n",
  1119. " <th></th>\n",
  1120. " <th></th>\n",
  1121. " <th></th>\n",
  1122. " </tr>\n",
  1123. " </thead>\n",
  1124. " <tbody>\n",
  1125. " <tr>\n",
  1126. " <th>Impressions</th>\n",
  1127. " <th>roas</th>\n",
  1128. " <th>conversions</th>\n",
  1129. " <th>-</th>\n",
  1130. " <td>16.98156</td>\n",
  1131. " <td>264.417576</td>\n",
  1132. " <td>1532.141534</td>\n",
  1133. " </tr>\n",
  1134. " </tbody>\n",
  1135. "</table>\n",
  1136. "</div>"
  1137. ],
  1138. "text/plain": [
  1139. " spend_prop imp_factor cpt\n",
  1140. "Billing Event AdsetStrategy strategy - \n",
  1141. "Impressions roas conversions - 16.98156 264.417576 1532.141534"
  1142. ]
  1143. },
  1144. "metadata": {},
  1145. "output_type": "display_data"
  1146. },
  1147. {
  1148. "data": {
  1149. "text/html": [
  1150. "<div>\n",
  1151. "<table border=\"1\" class=\"dataframe\">\n",
  1152. " <thead>\n",
  1153. " <tr style=\"text-align: right;\">\n",
  1154. " <th></th>\n",
  1155. " <th></th>\n",
  1156. " <th></th>\n",
  1157. " <th></th>\n",
  1158. " <th>spend_prop</th>\n",
  1159. " <th>imp_factor</th>\n",
  1160. " <th>cpt</th>\n",
  1161. " </tr>\n",
  1162. " <tr>\n",
  1163. " <th>Billing Event</th>\n",
  1164. " <th>Gender</th>\n",
  1165. " <th>Audience Types</th>\n",
  1166. " <th>Landing Pages</th>\n",
  1167. " <th></th>\n",
  1168. " <th></th>\n",
  1169. " <th></th>\n",
  1170. " </tr>\n",
  1171. " </thead>\n",
  1172. " <tbody>\n",
  1173. " <tr>\n",
  1174. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1175. " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
  1176. " <th>Interests</th>\n",
  1177. " <th>www.koovs.com/women/brand/masaba-x-koovs</th>\n",
  1178. " <td>1.649678</td>\n",
  1179. " <td>245.149379</td>\n",
  1180. " <td>4316.369000</td>\n",
  1181. " </tr>\n",
  1182. " <tr>\n",
  1183. " <th>Lookalike</th>\n",
  1184. " <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",
  1185. " <td>1.715253</td>\n",
  1186. " <td>179.234914</td>\n",
  1187. " <td>2087.416512</td>\n",
  1188. " </tr>\n",
  1189. " </tbody>\n",
  1190. "</table>\n",
  1191. "</div>"
  1192. ],
  1193. "text/plain": [
  1194. " spend_prop \\\n",
  1195. "Billing Event Gender Audience Types Landing Pages \n",
  1196. "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 1.649678 \n",
  1197. " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 1.715253 \n",
  1198. "\n",
  1199. " imp_factor \\\n",
  1200. "Billing Event Gender Audience Types Landing Pages \n",
  1201. "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 245.149379 \n",
  1202. " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 179.234914 \n",
  1203. "\n",
  1204. " cpt \n",
  1205. "Billing Event Gender Audience Types Landing Pages \n",
  1206. "Impressions Female Interests www.koovs.com/women/brand/masaba-x-koovs 4316.369000 \n",
  1207. " Lookalike www.koovs.com/women/dresses, www.koovs.com/wome... 2087.416512 "
  1208. ]
  1209. },
  1210. "metadata": {},
  1211. "output_type": "display_data"
  1212. },
  1213. {
  1214. "data": {
  1215. "text/html": [
  1216. "<div>\n",
  1217. "<table border=\"1\" class=\"dataframe\">\n",
  1218. " <thead>\n",
  1219. " <tr style=\"text-align: right;\">\n",
  1220. " <th></th>\n",
  1221. " <th></th>\n",
  1222. " <th></th>\n",
  1223. " <th></th>\n",
  1224. " <th>spend_prop</th>\n",
  1225. " <th>imp_factor</th>\n",
  1226. " <th>cpt</th>\n",
  1227. " </tr>\n",
  1228. " <tr>\n",
  1229. " <th>Billing Event</th>\n",
  1230. " <th>Gender</th>\n",
  1231. " <th>Audience Types</th>\n",
  1232. " <th>Age Range</th>\n",
  1233. " <th></th>\n",
  1234. " <th></th>\n",
  1235. " <th></th>\n",
  1236. " </tr>\n",
  1237. " </thead>\n",
  1238. " <tbody>\n",
  1239. " <tr>\n",
  1240. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1241. " <th>Female</th>\n",
  1242. " <th>Interests</th>\n",
  1243. " <th>18-40</th>\n",
  1244. " <td>1.649678</td>\n",
  1245. " <td>245.149379</td>\n",
  1246. " <td>4316.369000</td>\n",
  1247. " </tr>\n",
  1248. " <tr>\n",
  1249. " <th>Male</th>\n",
  1250. " <th>Interests</th>\n",
  1251. " <th>18-34</th>\n",
  1252. " <td>1.039295</td>\n",
  1253. " <td>228.524231</td>\n",
  1254. " <td>4532.178333</td>\n",
  1255. " </tr>\n",
  1256. " </tbody>\n",
  1257. "</table>\n",
  1258. "</div>"
  1259. ],
  1260. "text/plain": [
  1261. " spend_prop imp_factor \\\n",
  1262. "Billing Event Gender Audience Types Age Range \n",
  1263. "Impressions Female Interests 18-40 1.649678 245.149379 \n",
  1264. " Male Interests 18-34 1.039295 228.524231 \n",
  1265. "\n",
  1266. " cpt \n",
  1267. "Billing Event Gender Audience Types Age Range \n",
  1268. "Impressions Female Interests 18-40 4316.369000 \n",
  1269. " Male Interests 18-34 4532.178333 "
  1270. ]
  1271. },
  1272. "metadata": {},
  1273. "output_type": "display_data"
  1274. },
  1275. {
  1276. "data": {
  1277. "text/html": [
  1278. "<div>\n",
  1279. "<table border=\"1\" class=\"dataframe\">\n",
  1280. " <thead>\n",
  1281. " <tr style=\"text-align: right;\">\n",
  1282. " <th></th>\n",
  1283. " <th></th>\n",
  1284. " <th></th>\n",
  1285. " <th></th>\n",
  1286. " <th>spend_prop</th>\n",
  1287. " <th>imp_factor</th>\n",
  1288. " <th>cpt</th>\n",
  1289. " </tr>\n",
  1290. " <tr>\n",
  1291. " <th>Billing Event</th>\n",
  1292. " <th>Gender</th>\n",
  1293. " <th>Audience Types</th>\n",
  1294. " <th>-</th>\n",
  1295. " <th></th>\n",
  1296. " <th></th>\n",
  1297. " <th></th>\n",
  1298. " </tr>\n",
  1299. " </thead>\n",
  1300. " <tbody>\n",
  1301. " <tr>\n",
  1302. " <th>Impressions</th>\n",
  1303. " <th>Female</th>\n",
  1304. " <th>Interests</th>\n",
  1305. " <th>-</th>\n",
  1306. " <td>16.389444</td>\n",
  1307. " <td>234.799858</td>\n",
  1308. " <td>1880.82625</td>\n",
  1309. " </tr>\n",
  1310. " </tbody>\n",
  1311. "</table>\n",
  1312. "</div>"
  1313. ],
  1314. "text/plain": [
  1315. " spend_prop imp_factor cpt\n",
  1316. "Billing Event Gender Audience Types - \n",
  1317. "Impressions Female Interests - 16.389444 234.799858 1880.82625"
  1318. ]
  1319. },
  1320. "metadata": {},
  1321. "output_type": "display_data"
  1322. },
  1323. {
  1324. "data": {
  1325. "text/html": [
  1326. "<div>\n",
  1327. "<table border=\"1\" class=\"dataframe\">\n",
  1328. " <thead>\n",
  1329. " <tr style=\"text-align: right;\">\n",
  1330. " <th></th>\n",
  1331. " <th></th>\n",
  1332. " <th></th>\n",
  1333. " <th></th>\n",
  1334. " <th>spend_prop</th>\n",
  1335. " <th>imp_factor</th>\n",
  1336. " <th>cpt</th>\n",
  1337. " </tr>\n",
  1338. " <tr>\n",
  1339. " <th>Billing Event</th>\n",
  1340. " <th>Device Platforms</th>\n",
  1341. " <th>Publisher Platforms</th>\n",
  1342. " <th>Landing Pages</th>\n",
  1343. " <th></th>\n",
  1344. " <th></th>\n",
  1345. " <th></th>\n",
  1346. " </tr>\n",
  1347. " </thead>\n",
  1348. " <tbody>\n",
  1349. " <tr>\n",
  1350. " <th>Link_clicks</th>\n",
  1351. " <th>desktop or mobile</th>\n",
  1352. " <th>audience_network or facebook</th>\n",
  1353. " <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",
  1354. " <td>1.954581</td>\n",
  1355. " <td>230.161377</td>\n",
  1356. " <td>2764.402432</td>\n",
  1357. " </tr>\n",
  1358. " </tbody>\n",
  1359. "</table>\n",
  1360. "</div>"
  1361. ],
  1362. "text/plain": [
  1363. " spend_prop \\\n",
  1364. "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
  1365. "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 1.954581 \n",
  1366. "\n",
  1367. " imp_factor \\\n",
  1368. "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
  1369. "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 230.161377 \n",
  1370. "\n",
  1371. " cpt \n",
  1372. "Billing Event Device Platforms Publisher Platforms Landing Pages \n",
  1373. "Link_clicks desktop or mobile audience_network or facebook www.koovs.com/women/dresses, www.koovs.com/wome... 2764.402432 "
  1374. ]
  1375. },
  1376. "metadata": {},
  1377. "output_type": "display_data"
  1378. },
  1379. {
  1380. "data": {
  1381. "text/html": [
  1382. "<div>\n",
  1383. "<table border=\"1\" class=\"dataframe\">\n",
  1384. " <thead>\n",
  1385. " <tr style=\"text-align: right;\">\n",
  1386. " <th></th>\n",
  1387. " <th></th>\n",
  1388. " <th></th>\n",
  1389. " <th></th>\n",
  1390. " <th>spend_prop</th>\n",
  1391. " <th>imp_factor</th>\n",
  1392. " <th>cpt</th>\n",
  1393. " </tr>\n",
  1394. " <tr>\n",
  1395. " <th>Billing Event</th>\n",
  1396. " <th>Gender</th>\n",
  1397. " <th>Audience Types</th>\n",
  1398. " <th>Interests</th>\n",
  1399. " <th></th>\n",
  1400. " <th></th>\n",
  1401. " <th></th>\n",
  1402. " </tr>\n",
  1403. " </thead>\n",
  1404. " <tbody>\n",
  1405. " <tr>\n",
  1406. " <th>Impressions</th>\n",
  1407. " <th>Male</th>\n",
  1408. " <th>Interests</th>\n",
  1409. " <th>Allen Solly or Amazon.com or Beauty or Coupons or Discounts and allowances or Others</th>\n",
  1410. " <td>1.039295</td>\n",
  1411. " <td>228.524231</td>\n",
  1412. " <td>4532.178333</td>\n",
  1413. " </tr>\n",
  1414. " </tbody>\n",
  1415. "</table>\n",
  1416. "</div>"
  1417. ],
  1418. "text/plain": [
  1419. " spend_prop \\\n",
  1420. "Billing Event Gender Audience Types Interests \n",
  1421. "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 1.039295 \n",
  1422. "\n",
  1423. " imp_factor \\\n",
  1424. "Billing Event Gender Audience Types Interests \n",
  1425. "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 228.524231 \n",
  1426. "\n",
  1427. " cpt \n",
  1428. "Billing Event Gender Audience Types Interests \n",
  1429. "Impressions Male Interests Allen Solly or Amazon.com or Beauty or Coupons ... 4532.178333 "
  1430. ]
  1431. },
  1432. "metadata": {},
  1433. "output_type": "display_data"
  1434. },
  1435. {
  1436. "data": {
  1437. "text/html": [
  1438. "<div>\n",
  1439. "<table border=\"1\" class=\"dataframe\">\n",
  1440. " <thead>\n",
  1441. " <tr style=\"text-align: right;\">\n",
  1442. " <th></th>\n",
  1443. " <th></th>\n",
  1444. " <th></th>\n",
  1445. " <th></th>\n",
  1446. " <th>spend_prop</th>\n",
  1447. " <th>imp_factor</th>\n",
  1448. " <th>cpt</th>\n",
  1449. " </tr>\n",
  1450. " <tr>\n",
  1451. " <th>Billing Event</th>\n",
  1452. " <th>Device Platforms</th>\n",
  1453. " <th>Publisher Platforms</th>\n",
  1454. " <th>-</th>\n",
  1455. " <th></th>\n",
  1456. " <th></th>\n",
  1457. " <th></th>\n",
  1458. " </tr>\n",
  1459. " </thead>\n",
  1460. " <tbody>\n",
  1461. " <tr>\n",
  1462. " <th>Impressions</th>\n",
  1463. " <th>desktop or mobile</th>\n",
  1464. " <th>audience_network or facebook</th>\n",
  1465. " <th>-</th>\n",
  1466. " <td>26.106853</td>\n",
  1467. " <td>225.713802</td>\n",
  1468. " <td>1597.856269</td>\n",
  1469. " </tr>\n",
  1470. " </tbody>\n",
  1471. "</table>\n",
  1472. "</div>"
  1473. ],
  1474. "text/plain": [
  1475. " spend_prop \\\n",
  1476. "Billing Event Device Platforms Publisher Platforms - \n",
  1477. "Impressions desktop or mobile audience_network or facebook - 26.106853 \n",
  1478. "\n",
  1479. " imp_factor \\\n",
  1480. "Billing Event Device Platforms Publisher Platforms - \n",
  1481. "Impressions desktop or mobile audience_network or facebook - 225.713802 \n",
  1482. "\n",
  1483. " cpt \n",
  1484. "Billing Event Device Platforms Publisher Platforms - \n",
  1485. "Impressions desktop or mobile audience_network or facebook - 1597.856269 "
  1486. ]
  1487. },
  1488. "metadata": {},
  1489. "output_type": "display_data"
  1490. },
  1491. {
  1492. "data": {
  1493. "text/html": [
  1494. "<div>\n",
  1495. "<table border=\"1\" class=\"dataframe\">\n",
  1496. " <thead>\n",
  1497. " <tr style=\"text-align: right;\">\n",
  1498. " <th></th>\n",
  1499. " <th></th>\n",
  1500. " <th></th>\n",
  1501. " <th></th>\n",
  1502. " <th>spend_prop</th>\n",
  1503. " <th>imp_factor</th>\n",
  1504. " <th>cpt</th>\n",
  1505. " </tr>\n",
  1506. " <tr>\n",
  1507. " <th>Billing Event</th>\n",
  1508. " <th>Audience Strategy</th>\n",
  1509. " <th>Audience Types</th>\n",
  1510. " <th>-</th>\n",
  1511. " <th></th>\n",
  1512. " <th></th>\n",
  1513. " <th></th>\n",
  1514. " </tr>\n",
  1515. " </thead>\n",
  1516. " <tbody>\n",
  1517. " <tr>\n",
  1518. " <th>Impressions</th>\n",
  1519. " <th>Prospecting</th>\n",
  1520. " <th>Interests</th>\n",
  1521. " <th>-</th>\n",
  1522. " <td>28.146539</td>\n",
  1523. " <td>210.452198</td>\n",
  1524. " <td>1907.906062</td>\n",
  1525. " </tr>\n",
  1526. " </tbody>\n",
  1527. "</table>\n",
  1528. "</div>"
  1529. ],
  1530. "text/plain": [
  1531. " spend_prop imp_factor \\\n",
  1532. "Billing Event Audience Strategy Audience Types - \n",
  1533. "Impressions Prospecting Interests - 28.146539 210.452198 \n",
  1534. "\n",
  1535. " cpt \n",
  1536. "Billing Event Audience Strategy Audience Types - \n",
  1537. "Impressions Prospecting Interests - 1907.906062 "
  1538. ]
  1539. },
  1540. "metadata": {},
  1541. "output_type": "display_data"
  1542. }
  1543. ],
  1544. "source": [
  1545. "bad_new, bad_impacts = get_filtered_paths(bad_raw, True)\n",
  1546. "bad_impacts_list = [value[0] for value in bad_impacts]\n",
  1547. "for key in bad_impacts_list[0:15]:\n",
  1548. " if key in list(bad_new.keys()):\n",
  1549. " value = bad_new[key]\n",
  1550. " b = pd.DataFrame().from_dict(value, orient='index')\n",
  1551. " none_list = ['-']*len(tag_list)\n",
  1552. " l = list(key)\n",
  1553. " none_list[:len(l)] = l\n",
  1554. "\n",
  1555. " b.index = b.index.set_names(none_list)\n",
  1556. " b = b[b['imp_factor'] > 0.7*b.imp_factor.max()]\n",
  1557. " display(b)\n",
  1558. " "
  1559. ]
  1560. },
  1561. {
  1562. "cell_type": "markdown",
  1563. "metadata": {},
  1564. "source": [
  1565. "### Good Paths"
  1566. ]
  1567. },
  1568. {
  1569. "cell_type": "code",
  1570. "execution_count": 116,
  1571. "metadata": {
  1572. "collapsed": false,
  1573. "scrolled": false
  1574. },
  1575. "outputs": [
  1576. {
  1577. "data": {
  1578. "text/html": [
  1579. "<div>\n",
  1580. "<table border=\"1\" class=\"dataframe\">\n",
  1581. " <thead>\n",
  1582. " <tr style=\"text-align: right;\">\n",
  1583. " <th></th>\n",
  1584. " <th></th>\n",
  1585. " <th></th>\n",
  1586. " <th></th>\n",
  1587. " <th>spend_prop</th>\n",
  1588. " <th>imp_factor</th>\n",
  1589. " <th>cpt</th>\n",
  1590. " </tr>\n",
  1591. " <tr>\n",
  1592. " <th>Billing Event</th>\n",
  1593. " <th>Device Platforms</th>\n",
  1594. " <th>Locations</th>\n",
  1595. " <th>Age Range</th>\n",
  1596. " <th></th>\n",
  1597. " <th></th>\n",
  1598. " <th></th>\n",
  1599. " </tr>\n",
  1600. " </thead>\n",
  1601. " <tbody>\n",
  1602. " <tr>\n",
  1603. " <th>Impressions</th>\n",
  1604. " <th>desktop or mobile</th>\n",
  1605. " <th>IN</th>\n",
  1606. " <th>18-65</th>\n",
  1607. " <td>11.585272</td>\n",
  1608. " <td>164.974182</td>\n",
  1609. " <td>838.527331</td>\n",
  1610. " </tr>\n",
  1611. " </tbody>\n",
  1612. "</table>\n",
  1613. "</div>"
  1614. ],
  1615. "text/plain": [
  1616. " spend_prop imp_factor \\\n",
  1617. "Billing Event Device Platforms Locations Age Range \n",
  1618. "Impressions desktop or mobile IN 18-65 11.585272 164.974182 \n",
  1619. "\n",
  1620. " cpt \n",
  1621. "Billing Event Device Platforms Locations Age Range \n",
  1622. "Impressions desktop or mobile IN 18-65 838.527331 "
  1623. ]
  1624. },
  1625. "metadata": {},
  1626. "output_type": "display_data"
  1627. },
  1628. {
  1629. "data": {
  1630. "text/html": [
  1631. "<div>\n",
  1632. "<table border=\"1\" class=\"dataframe\">\n",
  1633. " <thead>\n",
  1634. " <tr style=\"text-align: right;\">\n",
  1635. " <th></th>\n",
  1636. " <th></th>\n",
  1637. " <th></th>\n",
  1638. " <th></th>\n",
  1639. " <th>spend_prop</th>\n",
  1640. " <th>imp_factor</th>\n",
  1641. " <th>cpt</th>\n",
  1642. " </tr>\n",
  1643. " <tr>\n",
  1644. " <th>Billing Event</th>\n",
  1645. " <th>AdsetStrategy</th>\n",
  1646. " <th>Audience Types</th>\n",
  1647. " <th>-</th>\n",
  1648. " <th></th>\n",
  1649. " <th></th>\n",
  1650. " <th></th>\n",
  1651. " </tr>\n",
  1652. " </thead>\n",
  1653. " <tbody>\n",
  1654. " <tr>\n",
  1655. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1656. " <th>roas</th>\n",
  1657. " <th>DPA</th>\n",
  1658. " <th>-</th>\n",
  1659. " <td>6.354514</td>\n",
  1660. " <td>123.662525</td>\n",
  1661. " <td>678.633878</td>\n",
  1662. " </tr>\n",
  1663. " <tr>\n",
  1664. " <th>visits</th>\n",
  1665. " <th>Lookalike</th>\n",
  1666. " <th>-</th>\n",
  1667. " <td>4.040858</td>\n",
  1668. " <td>146.426187</td>\n",
  1669. " <td>903.664145</td>\n",
  1670. " </tr>\n",
  1671. " </tbody>\n",
  1672. "</table>\n",
  1673. "</div>"
  1674. ],
  1675. "text/plain": [
  1676. " spend_prop imp_factor \\\n",
  1677. "Billing Event AdsetStrategy Audience Types - \n",
  1678. "Impressions roas DPA - 6.354514 123.662525 \n",
  1679. " visits Lookalike - 4.040858 146.426187 \n",
  1680. "\n",
  1681. " cpt \n",
  1682. "Billing Event AdsetStrategy Audience Types - \n",
  1683. "Impressions roas DPA - 678.633878 \n",
  1684. " visits Lookalike - 903.664145 "
  1685. ]
  1686. },
  1687. "metadata": {},
  1688. "output_type": "display_data"
  1689. },
  1690. {
  1691. "data": {
  1692. "text/html": [
  1693. "<div>\n",
  1694. "<table border=\"1\" class=\"dataframe\">\n",
  1695. " <thead>\n",
  1696. " <tr style=\"text-align: right;\">\n",
  1697. " <th></th>\n",
  1698. " <th></th>\n",
  1699. " <th></th>\n",
  1700. " <th></th>\n",
  1701. " <th>spend_prop</th>\n",
  1702. " <th>imp_factor</th>\n",
  1703. " <th>cpt</th>\n",
  1704. " </tr>\n",
  1705. " <tr>\n",
  1706. " <th>Billing Event</th>\n",
  1707. " <th>AdsetStrategy</th>\n",
  1708. " <th>Facebook Positions</th>\n",
  1709. " <th>-</th>\n",
  1710. " <th></th>\n",
  1711. " <th></th>\n",
  1712. " <th></th>\n",
  1713. " </tr>\n",
  1714. " </thead>\n",
  1715. " <tbody>\n",
  1716. " <tr>\n",
  1717. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1718. " <th>roas</th>\n",
  1719. " <th>feed or right_hand_column</th>\n",
  1720. " <th>-</th>\n",
  1721. " <td>9.085970</td>\n",
  1722. " <td>116.62279</td>\n",
  1723. " <td>840.048092</td>\n",
  1724. " </tr>\n",
  1725. " <tr>\n",
  1726. " <th>visits</th>\n",
  1727. " <th>feed</th>\n",
  1728. " <th>-</th>\n",
  1729. " <td>4.399702</td>\n",
  1730. " <td>143.51486</td>\n",
  1731. " <td>959.315125</td>\n",
  1732. " </tr>\n",
  1733. " </tbody>\n",
  1734. "</table>\n",
  1735. "</div>"
  1736. ],
  1737. "text/plain": [
  1738. " spend_prop \\\n",
  1739. "Billing Event AdsetStrategy Facebook Positions - \n",
  1740. "Impressions roas feed or right_hand_column - 9.085970 \n",
  1741. " visits feed - 4.399702 \n",
  1742. "\n",
  1743. " imp_factor \\\n",
  1744. "Billing Event AdsetStrategy Facebook Positions - \n",
  1745. "Impressions roas feed or right_hand_column - 116.62279 \n",
  1746. " visits feed - 143.51486 \n",
  1747. "\n",
  1748. " cpt \n",
  1749. "Billing Event AdsetStrategy Facebook Positions - \n",
  1750. "Impressions roas feed or right_hand_column - 840.048092 \n",
  1751. " visits feed - 959.315125 "
  1752. ]
  1753. },
  1754. "metadata": {},
  1755. "output_type": "display_data"
  1756. },
  1757. {
  1758. "data": {
  1759. "text/html": [
  1760. "<div>\n",
  1761. "<table border=\"1\" class=\"dataframe\">\n",
  1762. " <thead>\n",
  1763. " <tr style=\"text-align: right;\">\n",
  1764. " <th></th>\n",
  1765. " <th></th>\n",
  1766. " <th></th>\n",
  1767. " <th></th>\n",
  1768. " <th>spend_prop</th>\n",
  1769. " <th>imp_factor</th>\n",
  1770. " <th>cpt</th>\n",
  1771. " </tr>\n",
  1772. " <tr>\n",
  1773. " <th>Billing Event</th>\n",
  1774. " <th>Gender</th>\n",
  1775. " <th>Facebook Positions</th>\n",
  1776. " <th>Age Range</th>\n",
  1777. " <th></th>\n",
  1778. " <th></th>\n",
  1779. " <th></th>\n",
  1780. " </tr>\n",
  1781. " </thead>\n",
  1782. " <tbody>\n",
  1783. " <tr>\n",
  1784. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1785. " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
  1786. " <th>feed</th>\n",
  1787. " <th>18-45</th>\n",
  1788. " <td>9.794822</td>\n",
  1789. " <td>107.971959</td>\n",
  1790. " <td>1081.352996</td>\n",
  1791. " </tr>\n",
  1792. " <tr>\n",
  1793. " <th>feed or right_hand_column</th>\n",
  1794. " <th>18-65</th>\n",
  1795. " <td>3.595755</td>\n",
  1796. " <td>141.969523</td>\n",
  1797. " <td>1213.969355</td>\n",
  1798. " </tr>\n",
  1799. " </tbody>\n",
  1800. "</table>\n",
  1801. "</div>"
  1802. ],
  1803. "text/plain": [
  1804. " spend_prop \\\n",
  1805. "Billing Event Gender Facebook Positions Age Range \n",
  1806. "Impressions Female feed 18-45 9.794822 \n",
  1807. " feed or right_hand_column 18-65 3.595755 \n",
  1808. "\n",
  1809. " imp_factor \\\n",
  1810. "Billing Event Gender Facebook Positions Age Range \n",
  1811. "Impressions Female feed 18-45 107.971959 \n",
  1812. " feed or right_hand_column 18-65 141.969523 \n",
  1813. "\n",
  1814. " cpt \n",
  1815. "Billing Event Gender Facebook Positions Age Range \n",
  1816. "Impressions Female feed 18-45 1081.352996 \n",
  1817. " feed or right_hand_column 18-65 1213.969355 "
  1818. ]
  1819. },
  1820. "metadata": {},
  1821. "output_type": "display_data"
  1822. },
  1823. {
  1824. "data": {
  1825. "text/html": [
  1826. "<div>\n",
  1827. "<table border=\"1\" class=\"dataframe\">\n",
  1828. " <thead>\n",
  1829. " <tr style=\"text-align: right;\">\n",
  1830. " <th></th>\n",
  1831. " <th></th>\n",
  1832. " <th></th>\n",
  1833. " <th></th>\n",
  1834. " <th>spend_prop</th>\n",
  1835. " <th>imp_factor</th>\n",
  1836. " <th>cpt</th>\n",
  1837. " </tr>\n",
  1838. " <tr>\n",
  1839. " <th>Billing Event</th>\n",
  1840. " <th>Gender</th>\n",
  1841. " <th>Facebook Positions</th>\n",
  1842. " <th>Custom Audiences</th>\n",
  1843. " <th></th>\n",
  1844. " <th></th>\n",
  1845. " <th></th>\n",
  1846. " </tr>\n",
  1847. " </thead>\n",
  1848. " <tbody>\n",
  1849. " <tr>\n",
  1850. " <th rowspan=\"2\" valign=\"top\">Impressions</th>\n",
  1851. " <th rowspan=\"2\" valign=\"top\">Female</th>\n",
  1852. " <th>feed</th>\n",
  1853. " <th>Lookalike (IN, 1%) - loyal_purchasers_data_20160415</th>\n",
  1854. " <td>9.731727</td>\n",
  1855. " <td>110.844955</td>\n",
  1856. " <td>1076.658732</td>\n",
  1857. " </tr>\n",
  1858. " <tr>\n",
  1859. " <th>feed or right_hand_column</th>\n",
  1860. " <th>ECOMMERCE MOBILE & EMAIL IDS FEB 2017</th>\n",
  1861. " <td>3.595755</td>\n",
  1862. " <td>141.969523</td>\n",
  1863. " <td>1213.969355</td>\n",
  1864. " </tr>\n",
  1865. " </tbody>\n",
  1866. "</table>\n",
  1867. "</div>"
  1868. ],
  1869. "text/plain": [
  1870. " spend_prop \\\n",
  1871. "Billing Event Gender Facebook Positions Custom Audiences \n",
  1872. "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 9.731727 \n",
  1873. " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 3.595755 \n",
  1874. "\n",
  1875. " imp_factor \\\n",
  1876. "Billing Event Gender Facebook Positions Custom Audiences \n",
  1877. "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 110.844955 \n",
  1878. " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 141.969523 \n",
  1879. "\n",
  1880. " cpt \n",
  1881. "Billing Event Gender Facebook Positions Custom Audiences \n",
  1882. "Impressions Female feed Lookalike (IN, 1%) - loyal_purchasers_data_2016... 1076.658732 \n",
  1883. " feed or right_hand_column ECOMMERCE MOBILE & EMAIL IDS FEB 2017 1213.969355 "
  1884. ]
  1885. },
  1886. "metadata": {},
  1887. "output_type": "display_data"
  1888. },
  1889. {
  1890. "data": {
  1891. "text/html": [
  1892. "<div>\n",
  1893. "<table border=\"1\" class=\"dataframe\">\n",
  1894. " <thead>\n",
  1895. " <tr style=\"text-align: right;\">\n",
  1896. " <th></th>\n",
  1897. " <th></th>\n",
  1898. " <th></th>\n",
  1899. " <th></th>\n",
  1900. " <th>spend_prop</th>\n",
  1901. " <th>imp_factor</th>\n",
  1902. " <th>cpt</th>\n",
  1903. " </tr>\n",
  1904. " <tr>\n",
  1905. " <th>Billing Event</th>\n",
  1906. " <th>Device Platforms</th>\n",
  1907. " <th>Facebook Positions</th>\n",
  1908. " <th>Landing Pages</th>\n",
  1909. " <th></th>\n",
  1910. " <th></th>\n",
  1911. " <th></th>\n",
  1912. " </tr>\n",
  1913. " </thead>\n",
  1914. " <tbody>\n",
  1915. " <tr>\n",
  1916. " <th>Impressions</th>\n",
  1917. " <th>desktop or mobile</th>\n",
  1918. " <th>feed or right_hand_column</th>\n",
  1919. " <th>koovs.com</th>\n",
  1920. " <td>6.354514</td>\n",
  1921. " <td>136.237021</td>\n",
  1922. " <td>678.633878</td>\n",
  1923. " </tr>\n",
  1924. " </tbody>\n",
  1925. "</table>\n",
  1926. "</div>"
  1927. ],
  1928. "text/plain": [
  1929. " spend_prop \\\n",
  1930. "Billing Event Device Platforms Facebook Positions Landing Pages \n",
  1931. "Impressions desktop or mobile feed or right_hand_column koovs.com 6.354514 \n",
  1932. "\n",
  1933. " imp_factor \\\n",
  1934. "Billing Event Device Platforms Facebook Positions Landing Pages \n",
  1935. "Impressions desktop or mobile feed or right_hand_column koovs.com 136.237021 \n",
  1936. "\n",
  1937. " cpt \n",
  1938. "Billing Event Device Platforms Facebook Positions Landing Pages \n",
  1939. "Impressions desktop or mobile feed or right_hand_column koovs.com 678.633878 "
  1940. ]
  1941. },
  1942. "metadata": {},
  1943. "output_type": "display_data"
  1944. },
  1945. {
  1946. "data": {
  1947. "text/html": [
  1948. "<div>\n",
  1949. "<table border=\"1\" class=\"dataframe\">\n",
  1950. " <thead>\n",
  1951. " <tr style=\"text-align: right;\">\n",
  1952. " <th></th>\n",
  1953. " <th></th>\n",
  1954. " <th></th>\n",
  1955. " <th></th>\n",
  1956. " <th>spend_prop</th>\n",
  1957. " <th>imp_factor</th>\n",
  1958. " <th>cpt</th>\n",
  1959. " </tr>\n",
  1960. " <tr>\n",
  1961. " <th>Billing Event</th>\n",
  1962. " <th>Ad Type</th>\n",
  1963. " <th>strategy</th>\n",
  1964. " <th>Lookalike Types</th>\n",
  1965. " <th></th>\n",
  1966. " <th></th>\n",
  1967. " <th></th>\n",
  1968. " </tr>\n",
  1969. " </thead>\n",
  1970. " <tbody>\n",
  1971. " <tr>\n",
  1972. " <th>Impressions</th>\n",
  1973. " <th>Carousel</th>\n",
  1974. " <th>conversions</th>\n",
  1975. " <th>1%</th>\n",
  1976. " <td>14.408359</td>\n",
  1977. " <td>126.649392</td>\n",
  1978. " <td>1176.266661</td>\n",
  1979. " </tr>\n",
  1980. " </tbody>\n",
  1981. "</table>\n",
  1982. "</div>"
  1983. ],
  1984. "text/plain": [
  1985. " spend_prop imp_factor \\\n",
  1986. "Billing Event Ad Type strategy Lookalike Types \n",
  1987. "Impressions Carousel conversions 1% 14.408359 126.649392 \n",
  1988. "\n",
  1989. " cpt \n",
  1990. "Billing Event Ad Type strategy Lookalike Types \n",
  1991. "Impressions Carousel conversions 1% 1176.266661 "
  1992. ]
  1993. },
  1994. "metadata": {},
  1995. "output_type": "display_data"
  1996. },
  1997. {
  1998. "data": {
  1999. "text/html": [
  2000. "<div>\n",
  2001. "<table border=\"1\" class=\"dataframe\">\n",
  2002. " <thead>\n",
  2003. " <tr style=\"text-align: right;\">\n",
  2004. " <th></th>\n",
  2005. " <th></th>\n",
  2006. " <th></th>\n",
  2007. " <th></th>\n",
  2008. " <th>spend_prop</th>\n",
  2009. " <th>imp_factor</th>\n",
  2010. " <th>cpt</th>\n",
  2011. " </tr>\n",
  2012. " <tr>\n",
  2013. " <th>Billing Event</th>\n",
  2014. " <th>Audience Strategy</th>\n",
  2015. " <th>strategy</th>\n",
  2016. " <th>Lookalike Types</th>\n",
  2017. " <th></th>\n",
  2018. " <th></th>\n",
  2019. " <th></th>\n",
  2020. " </tr>\n",
  2021. " </thead>\n",
  2022. " <tbody>\n",
  2023. " <tr>\n",
  2024. " <th>Impressions</th>\n",
  2025. " <th>Prospecting</th>\n",
  2026. " <th>conversions</th>\n",
  2027. " <th>1%</th>\n",
  2028. " <td>14.408359</td>\n",
  2029. " <td>126.649392</td>\n",
  2030. " <td>1176.266661</td>\n",
  2031. " </tr>\n",
  2032. " </tbody>\n",
  2033. "</table>\n",
  2034. "</div>"
  2035. ],
  2036. "text/plain": [
  2037. " spend_prop \\\n",
  2038. "Billing Event Audience Strategy strategy Lookalike Types \n",
  2039. "Impressions Prospecting conversions 1% 14.408359 \n",
  2040. "\n",
  2041. " imp_factor \\\n",
  2042. "Billing Event Audience Strategy strategy Lookalike Types \n",
  2043. "Impressions Prospecting conversions 1% 126.649392 \n",
  2044. "\n",
  2045. " cpt \n",
  2046. "Billing Event Audience Strategy strategy Lookalike Types \n",
  2047. "Impressions Prospecting conversions 1% 1176.266661 "
  2048. ]
  2049. },
  2050. "metadata": {},
  2051. "output_type": "display_data"
  2052. },
  2053. {
  2054. "data": {
  2055. "text/html": [
  2056. "<div>\n",
  2057. "<table border=\"1\" class=\"dataframe\">\n",
  2058. " <thead>\n",
  2059. " <tr style=\"text-align: right;\">\n",
  2060. " <th></th>\n",
  2061. " <th></th>\n",
  2062. " <th></th>\n",
  2063. " <th></th>\n",
  2064. " <th>spend_prop</th>\n",
  2065. " <th>imp_factor</th>\n",
  2066. " <th>cpt</th>\n",
  2067. " </tr>\n",
  2068. " <tr>\n",
  2069. " <th>Billing Event</th>\n",
  2070. " <th>Campaign Objective</th>\n",
  2071. " <th>strategy</th>\n",
  2072. " <th>Lookalike Types</th>\n",
  2073. " <th></th>\n",
  2074. " <th></th>\n",
  2075. " <th></th>\n",
  2076. " </tr>\n",
  2077. " </thead>\n",
  2078. " <tbody>\n",
  2079. " <tr>\n",
  2080. " <th>Impressions</th>\n",
  2081. " <th>Conversions</th>\n",
  2082. " <th>conversions</th>\n",
  2083. " <th>1%</th>\n",
  2084. " <td>14.408359</td>\n",
  2085. " <td>126.649392</td>\n",
  2086. " <td>1176.266661</td>\n",
  2087. " </tr>\n",
  2088. " </tbody>\n",
  2089. "</table>\n",
  2090. "</div>"
  2091. ],
  2092. "text/plain": [
  2093. " spend_prop \\\n",
  2094. "Billing Event Campaign Objective strategy Lookalike Types \n",
  2095. "Impressions Conversions conversions 1% 14.408359 \n",
  2096. "\n",
  2097. " imp_factor \\\n",
  2098. "Billing Event Campaign Objective strategy Lookalike Types \n",
  2099. "Impressions Conversions conversions 1% 126.649392 \n",
  2100. "\n",
  2101. " cpt \n",
  2102. "Billing Event Campaign Objective strategy Lookalike Types \n",
  2103. "Impressions Conversions conversions 1% 1176.266661 "
  2104. ]
  2105. },
  2106. "metadata": {},
  2107. "output_type": "display_data"
  2108. },
  2109. {
  2110. "data": {
  2111. "text/html": [
  2112. "<div>\n",
  2113. "<table border=\"1\" class=\"dataframe\">\n",
  2114. " <thead>\n",
  2115. " <tr style=\"text-align: right;\">\n",
  2116. " <th></th>\n",
  2117. " <th></th>\n",
  2118. " <th></th>\n",
  2119. " <th></th>\n",
  2120. " <th>spend_prop</th>\n",
  2121. " <th>imp_factor</th>\n",
  2122. " <th>cpt</th>\n",
  2123. " </tr>\n",
  2124. " <tr>\n",
  2125. " <th>Billing Event</th>\n",
  2126. " <th>Device Platforms</th>\n",
  2127. " <th>Locations</th>\n",
  2128. " <th>Landing Pages</th>\n",
  2129. " <th></th>\n",
  2130. " <th></th>\n",
  2131. " <th></th>\n",
  2132. " </tr>\n",
  2133. " </thead>\n",
  2134. " <tbody>\n",
  2135. " <tr>\n",
  2136. " <th>Impressions</th>\n",
  2137. " <th>desktop or mobile</th>\n",
  2138. " <th>IN</th>\n",
  2139. " <th>koovs.com</th>\n",
  2140. " <td>6.354514</td>\n",
  2141. " <td>125.464367</td>\n",
  2142. " <td>678.633878</td>\n",
  2143. " </tr>\n",
  2144. " </tbody>\n",
  2145. "</table>\n",
  2146. "</div>"
  2147. ],
  2148. "text/plain": [
  2149. " spend_prop \\\n",
  2150. "Billing Event Device Platforms Locations Landing Pages \n",
  2151. "Impressions desktop or mobile IN koovs.com 6.354514 \n",
  2152. "\n",
  2153. " imp_factor \\\n",
  2154. "Billing Event Device Platforms Locations Landing Pages \n",
  2155. "Impressions desktop or mobile IN koovs.com 125.464367 \n",
  2156. "\n",
  2157. " cpt \n",
  2158. "Billing Event Device Platforms Locations Landing Pages \n",
  2159. "Impressions desktop or mobile IN koovs.com 678.633878 "
  2160. ]
  2161. },
  2162. "metadata": {},
  2163. "output_type": "display_data"
  2164. }
  2165. ],
  2166. "source": [
  2167. "good_new, good_impacts = get_filtered_paths(good_raw, True)\n",
  2168. "good_impacts_list = [value[0] for value in good_impacts]\n",
  2169. "for key in good_impacts_list[0:10]:\n",
  2170. " if key in list(good_new.keys()):\n",
  2171. " value = good_new[key]\n",
  2172. " b = pd.DataFrame().from_dict(value, orient='index')\n",
  2173. " none_list = ['-']*len(tag_list)\n",
  2174. " l = list(key)\n",
  2175. " none_list[:len(l)] = l\n",
  2176. "\n",
  2177. " b.index = b.index.set_names(none_list)\n",
  2178. " b = b[b['imp_factor'] > 0.7*b.imp_factor.max()]\n",
  2179. "\n",
  2180. " display(b)"
  2181. ]
  2182. },
  2183. {
  2184. "cell_type": "code",
  2185. "execution_count": 117,
  2186. "metadata": {
  2187. "collapsed": false
  2188. },
  2189. "outputs": [],
  2190. "source": [
  2191. "strat_df = df.groupby(['Billing Event', 'Device Platforms', 'Audience Types']).sum()"
  2192. ]
  2193. },
  2194. {
  2195. "cell_type": "code",
  2196. "execution_count": 118,
  2197. "metadata": {
  2198. "collapsed": false
  2199. },
  2200. "outputs": [],
  2201. "source": [
  2202. "strat_df['prop'] = strat_df.fb_spend / df.fb_spend.sum()\n",
  2203. "strat_df['cpt'] = strat_df.fb_spend / strat_df.ga_transactions"
  2204. ]
  2205. },
  2206. {
  2207. "cell_type": "code",
  2208. "execution_count": null,
  2209. "metadata": {
  2210. "collapsed": false
  2211. },
  2212. "outputs": [],
  2213. "source": [
  2214. "strat_df.iloc[strat_df.index.get_level_values('Audience Types') == 'Interests']"
  2215. ]
  2216. },
  2217. {
  2218. "cell_type": "code",
  2219. "execution_count": null,
  2220. "metadata": {
  2221. "collapsed": true
  2222. },
  2223. "outputs": [],
  2224. "source": []
  2225. }
  2226. ],
  2227. "metadata": {
  2228. "anaconda-cloud": {},
  2229. "kernelspec": {
  2230. "display_name": "Python [jarvis1]",
  2231. "language": "python",
  2232. "name": "Python [jarvis1]"
  2233. },
  2234. "language_info": {
  2235. "codemirror_mode": {
  2236. "name": "ipython",
  2237. "version": 3
  2238. },
  2239. "file_extension": ".py",
  2240. "mimetype": "text/x-python",
  2241. "name": "python",
  2242. "nbconvert_exporter": "python",
  2243. "pygments_lexer": "ipython3",
  2244. "version": "3.5.2"
  2245. }
  2246. },
  2247. "nbformat": 4,
  2248. "nbformat_minor": 0
  2249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement