{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "703323ef-8da7-0852-2529-78bb8d5ce9d9"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "19b237ae-da5f-f4c5-5686-ab36f6b8e83b"
      },
      "outputs": [],
      "source": [
        "events = pd.read_csv('../input/events.csv', usecols=['display_id', 'uuid'])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3690f8e5-679d-73cb-a9c8-b4271d4b7253"
      },
      "outputs": [],
      "source": [
        "train = pd.read_csv('../input/clicks_train.csv')\n",
        "train_clicked = train[train.clicked==1]\n",
        "del train"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "62c80722-8a35-ebf7-0b6e-ab4bd0652de3"
      },
      "outputs": [],
      "source": [
        "train_clicked = pd.merge(train_clicked, events, how='left', on='display_id')\n",
        "# combinding uuid to specify each user"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "cec5a380-368d-b96c-bb89-965180ad4954"
      },
      "outputs": [],
      "source": [
        "train_clicked.head()\n",
        "uuid_grouped = train_clicked.groupby('uuid')['ad_id']"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "f8e79d2c-397e-152a-829d-8a134f73343b"
      },
      "outputs": [],
      "source": [
        "count = 0\n",
        "for uuid, ads in uuid_grouped:\n",
        "    if len(ads) != 1:\n",
        "        if len(ads) != len(ads.unique()):\n",
        "            count += 1"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "a967fcda-7f58-05ab-94e1-49f0e53b07c6"
      },
      "source": [
        "<h1>Conclusion</h1>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "228527d2-01e1-27c2-cd1c-90dd7ae9854f"
      },
      "outputs": [],
      "source": [
        "num = count / len(train_clicked.uuid.unique()) * 100\n",
        "print('{}%'.format(round(num, 5)))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "fb2d3470-3baa-849b-79e8-fa292519d877"
      },
      "source": [
        "<h3>So, most of people click a ad just once.\u00af\\_(\u30c4) _/\u00af</h3>"
      ]
    }
  ],
  "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
}