{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "import dataiku\n",
    "from dataiku import pandasutils as pdu\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read the dataset as a Pandas dataframe in memory\n",
    "# Note: here, we only read the first 100K rows. Other sampling options are available\n",
    "dataset_orders = dataiku.Dataset(\"orders\")\n",
    "df = dataset_orders.get_dataframe(limit=100000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get some simple descriptive statistics\n",
    "pdu.audit(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.assign(total=df.tshirt_price*df.tshirt_quantity\n",
    "         ).groupby(by=\"customer_id\"\n",
    "                  ).agg({\"pages_visited\":\"mean\",\n",
    "                         \"total\":\"sum\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_customers = dataiku.Dataset(\"customers_prepared\")\n",
    "dfCustomers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Recipe outputs\n",
    "orders_by_customer = dataiku.Dataset(\"orders_by_customer\")\n",
    "orders_by_customer.write_with_schema(df)"
   ]
  }
 ],
 "metadata": {
  "associatedRecipe": "recipe from notebook Python analysis of orders",
  "creator": "alex",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  },
  "tags": [
   "recipe-editor"
  ]
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
