{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "2f7036db-cb1f-260a-e860-583a8f04a17a"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "bdcd6649-efc6-7ec4-06f2-c3741d68266b"
      },
      "outputs": [],
      "source": [
        "train = pd.read_csv('../input/clicks_train.csv', nrows=1000000)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "c018f57d-07f7-d210-3905-a06a45124c72"
      },
      "outputs": [],
      "source": [
        "train.info()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "1c291c37-80e5-d755-9c2f-b442b21cc16e"
      },
      "outputs": [],
      "source": [
        "events = pd.read_csv('../input/events.csv', usecols=['display_id', 'uuid'])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "84195f17-2915-36d9-7783-0ba51b949fea"
      },
      "outputs": [],
      "source": [
        "events.info()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "1af030ef-ea81-b022-c22a-9541d64e9b15"
      },
      "outputs": [],
      "source": [
        "events = events.merge(train, how='inner', on='display_id')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6f0d3794-e0d6-3dfc-13a4-96148e52f287"
      },
      "outputs": [],
      "source": [
        "events.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "abb0d276-8885-56d4-c6c5-6d6f88867bdc"
      },
      "outputs": [],
      "source": [
        "tmp = events[events['clicked']==1].groupby('uuid')['ad_id'].apply(list).reset_index()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "96415de5-6eb0-a7fb-41c7-7c057298261f"
      },
      "outputs": [],
      "source": [
        "tmp[tmp['ad_id'].apply(lambda x: len(x) > 1)]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "90667d5c-c92d-be1b-ac62-a02bea47f5af"
      },
      "outputs": [],
      "source": ""
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "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
}