{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "4ce9a89f-19b7-a102-a401-dd85e1a1c057"
      },
      "source": [
        "Here is code to randomly shuffle every ad_id list in submission file"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "58eb7e2c-64f1-50ac-794c-93bcf3d5c5bb"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import zipfile"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "5df11bbf-67d8-3b8a-6931-730bbe75d477"
      },
      "outputs": [],
      "source": [
        "submission = pd.read_csv('../input/sample_submission.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "34c5e22a-3b69-23c0-6389-05f78d32019e"
      },
      "outputs": [],
      "source": [
        "submission.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "10792fea-3105-6205-0c0d-b0a052e55470"
      },
      "outputs": [],
      "source": [
        "def getShuffledList(ad_id_string):\n",
        "    tmp = np.array(ad_id_string.split())\n",
        "    np.random.shuffle(tmp)\n",
        "    return ' '.join(tmp)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "47be1526-d95c-bd41-b2e3-5d26e9d7087e"
      },
      "outputs": [],
      "source": [
        "submission['ad_id'] = submission['ad_id'].apply(lambda x: getShuffledList(x))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "4e8fc041-9e02-c169-3826-7785a080eca9"
      },
      "outputs": [],
      "source": [
        "submission.head()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "107166a7-3558-8305-03af-60d86c097534"
      },
      "outputs": [],
      "source": [
        "submission.to_csv('submission_shuffled.csv', index=False)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "b849e8fe-3fc5-2af0-4c82-f63447354c6e"
      },
      "outputs": [],
      "source": [
        "with zipfile.ZipFile('submission_shuffled.csv.zip', 'w', zipfile.ZIP_DEFLATED) as myzip:\n",
        "    myzip.write('submission_shuffled.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "841360dc-4a55-6b49-3b05-ad29d71d2d4f"
      },
      "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
}