{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "72f4d8de-b402-547a-4ba0-bb814cf9ad7c"
      },
      "outputs": [],
      "source": [
        "# This Python 3 environment comes with many helpful analytics libraries installed\n",
        "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
        "# For example, here's several helpful packages to load in \n",
        "\n",
        "import numpy as np # linear algebra\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "\n",
        "# Input data files are available in the \"../input/\" directory.\n",
        "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n",
        "\n",
        "from subprocess import check_output\n",
        "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n",
        "\n",
        "# Any results you write to the current directory are saved as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "869dddc1-f017-d752-0fc7-c8f0d2d650f1"
      },
      "outputs": [],
      "source": [
        "cate = pd.read_csv('../input/documents_categories.csv')\n",
        "cate.rename(columns = {'confidence_level':'cl_category'}, inplace = True)\n",
        "cate=cate.iloc[cate.groupby('document_id')['cl_category'].agg(pd.Series.idxmax)]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6e05cdbe-9c8c-dd70-599e-02d2b8dd811f"
      },
      "outputs": [],
      "source": [
        "cate[0:5]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "734ef6a0-0b9d-db63-0347-8eacc531e421"
      },
      "outputs": [],
      "source": [
        "entity = pd.read_csv('../input/documents_entities.csv')\n",
        "entity.rename(columns = {'confidence_level':'cl_entity'}, inplace = True)\n",
        "entity=entity.iloc[entity.groupby('document_id')['cl_entity'].agg(pd.Series.idxmax)]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "0e323f9b-e28c-914c-2f2e-74286311529e"
      },
      "outputs": [],
      "source": [
        "entity[0:5]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "2d90f4c6-cbcc-c1a2-6376-116defc2e930"
      },
      "outputs": [],
      "source": [
        "meta = pd.read_csv(\"../input/documents_meta.csv\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a927bade-536e-f409-5585-ddbd8c6d72b2"
      },
      "outputs": [],
      "source": [
        "meta[0:5]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "f82939ee-3e42-90bd-686a-ff08e0d8c5af"
      },
      "outputs": [],
      "source": [
        "topics = pd.read_csv('../input/documents_topics.csv')\n",
        "topics.rename(columns = {'confidence_level':'cl_topic'}, inplace = True)\n",
        "topics=topics.iloc[topics.groupby('document_id')['cl_topic'].agg(pd.Series.idxmax)]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "02d241db-0b6e-f83f-37f1-927998b48cfa"
      },
      "outputs": [],
      "source": [
        "topics[0:5]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "8663945e-7753-7e09-b5ba-b26e5e90ccc6"
      },
      "outputs": [],
      "source": [
        "documents = [entity,meta,topics]\n",
        "base =cate\n",
        "for doc in documents:\n",
        "    base = base.merge(doc,how='outer',left_on='document_id',right_on='document_id')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "cadee2da-c5b1-9574-008a-e7f95ac41d60"
      },
      "outputs": [],
      "source": [
        "base[0:5]"
      ]
    }
  ],
  "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.6.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}