/DynamicPricingAlgo .ipynb
Jupyter | 496 lines | 496 code | 0 blank | 0 comment | 0 complexity | 009e42546622f3fcc6d6fcbc22ba8029 MD5 | raw file
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "<pandas.io.excel.ExcelFile at 0x114f008d0>"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "data = pd.ExcelFile(\"Breakfast.xlsx\")\n",
- "data"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df = data.parse('dh Transaction Data')\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df1 = df.ix[1:]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "4"
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "'''##################Testing Similarity between Matlab & R#################\n",
- "\n",
- "################## Indexing similarities & Differences #################\n",
- "length(value)\n",
- "i=4\n",
- "Bolts[1:i,1:i]\n",
- "\n",
- "Bolts[':',1:i]#To be typed within quotes is the difference\n",
- "\n",
- "Bolts[c(1,3),c(1,3)]#Need to check for this functionality in matlab\n",
- "'''\n",
- "4"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>Unnamed: 1</th>\n",
- " <th>Unnamed: 2</th>\n",
- " <th>Unnamed: 3</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>1</th>\n",
- " <td>367</td>\n",
- " <td>1111009477</td>\n",
- " <td>13</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>2</th>\n",
- " <td>367</td>\n",
- " <td>1111009497</td>\n",
- " <td>20</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>3</th>\n",
- " <td>367</td>\n",
- " <td>1111009507</td>\n",
- " <td>14</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>4</th>\n",
- " <td>367</td>\n",
- " <td>1111035398</td>\n",
- " <td>4</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>5</th>\n",
- " <td>367</td>\n",
- " <td>1111038078</td>\n",
- " <td>3</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " Unnamed: 1 Unnamed: 2 Unnamed: 3\n",
- "1 367 1111009477 13\n",
- "2 367 1111009497 20\n",
- "3 367 1111009507 14\n",
- "4 367 1111035398 4\n",
- "5 367 1111038078 3"
- ]
- },
- "execution_count": 28,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "#df1.loc['d':,'A':'C']\n",
- "#df.loc[1:5,'Unnamed: 1':'Unnamed: 3']\n",
- "#Removing the 1st row\n",
- "3\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "\n",
- "#Connecting to Mongo\n",
- "'''\n",
- "Method 1\n",
- "import pandas as pd\n",
- "from pymongo import MongoClient\n",
- "\n",
- "\n",
- "def _connect_mongo(host, port, username, password, db):\n",
- " \"\"\" A util for making a connection to mongo \"\"\"\n",
- "\n",
- " if username and password:\n",
- " mongo_uri = 'mongodb://%s:%s@%s:%s/%s' % (username, password, host, port, db)\n",
- " conn = MongoClient(mongo_uri)\n",
- " else:\n",
- " conn = MongoClient(host, port)\n",
- "\n",
- "\n",
- " return conn[db]\n",
- "\n",
- "\n",
- "def read_mongo(db, collection, query={}, host='localhost', port=27017, username=None, password=None, no_id=True):\n",
- " \"\"\" Read from Mongo and Store into DataFrame \"\"\"\n",
- "\n",
- " # Connect to MongoDB\n",
- " db = _connect_mongo(host=host, port=port, username=username, password=password, db=db)\n",
- "\n",
- " # Make a query to the specific DB and Collection\n",
- " cursor = db[collection].find(query)\n",
- "\n",
- " # Expand the cursor and construct the DataFrame\n",
- " df = pd.DataFrame(list(cursor))\n",
- "\n",
- " # Delete the _id\n",
- " if no_id:\n",
- " del df['_id']\n",
- "\n",
- " return df\n",
- "'''\n",
- "'''\n",
- "#Method 2\n",
- "\n",
- "import pymongo\n",
- "import pandas as pd\n",
- "from pymongo import Connection\n",
- "connection = Connection()\n",
- "db = connection.immibytes\n",
- "input_data = db.myCollection\n",
- "data = pd.DataFrame(list(input_data.find()))\n",
- "'''\n",
- "#Method 3\n",
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "\n",
- "from pymongo import MongoClient\n",
- "uri = \"mongodb://poc_user:pocatimmibytes@ec2-52-37-213-141.us-west-2.compute.amazonaws.com/immibytes\";\n",
- "client = MongoClient(uri)\n",
- "db = client.immibytes\n",
- "input_data = db.myCollection\n",
- "#cursor=db['myCollection'].find({})\n",
- "#list(db.myCollection.find({}))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "#df = pd.DataFrame(list(db.myCollection.find({})))\n",
- "import pymongo\n",
- "import pandas as pd\n",
- "#from pymongo import Connection\n",
- "from pymongo import MongoClient\n",
- "c = MongoClient()\n",
- "#from mogo import connect as PyConnection\n",
- "#connection = Connection()\n",
- "db = c.immibytes\n",
- "\n",
- "#input_data = db.transaction_50k.find({\"PROD_CODE_40\":\"D00001\"})\n",
- "\n",
- "#input_data = db.transaction_50k"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 99,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "#D1 = db['D1'].find({})\n",
- " \n",
- "#D4 = db['D4'].find({})\n",
- "#D5 = db['D5'].find({})\n",
- "#D6 = db['D6'].find({})\n",
- "#D7 = db['D7'].find({})\n",
- "#D8 = db['D8'].find({})\n",
- "D9 = db['D9'].find({})"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 100,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "#df3 = pd.DataFrame(list(input_data3))\n",
- "\n",
- "#PD1=pd.DataFrame(list(D1))\n",
- "\n",
- "#PD4=pd.DataFrame(list(D4))\n",
- "#PD5=pd.DataFrame(list(D5))\n",
- "#PD6=pd.DataFrame(list(D6))\n",
- "#PD7=pd.DataFrame(list(D7))\n",
- "#PD8=pd.DataFrame(list(D8))\n",
- "#PD9=pd.DataFrame(list(D9))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 122,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "5"
- ]
- },
- "execution_count": 122,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "#df2\n",
- "#PD9\n",
- "5"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 154,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "#PD1.to_csv('Data1.csv')\n",
- "#PD2.to_csv('Data2.csv')\n",
- "#D2G4.to_csv('Data2G4.csv')\n",
- "#D2G5.to_csv('Data2G5.csv')\n",
- "#D2G6.to_csv('Data2G6.csv')\n",
- "#D2G7.to_csv('Data2G7.csv')-Not yet done\n",
- "#D2G8.to_csv('Data2G8.csv')\n",
- "#D2G9.to_csv('Data2G9.csv')\n",
- "\n",
- "#D3G10.to_csv('Data3G10.csv')\n",
- "#D3G11.to_csv('Data3G11.csv')\n",
- "#D3G12.to_csv('Data3G12.csv')\n",
- "#D3G13.to_csv('Data3G13.csv')\n",
- "#D3G14.to_csv('Data3G14.csv')\n",
- "#D3G15.to_csv('Data3G15.csv')\n",
- "D3G16.to_csv('Data3G16.csv')\n",
- "\n",
- "\n",
- "#PD4.to_csv('Data4.csv')\n",
- "#PD5.to_csv('Data5.csv')\n",
- "#PD6.to_csv('Data6.csv')\n",
- "#PD7.to_csv('Data7.csv')\n",
- "#PD8.to_csv('Data8.csv')\n",
- "#PD9.to_csv('Data9.csv')\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 153,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "#list(db.transaction_5k.find({}))\n",
- "#DDist1=pd.DataFrame(list(db.D3.distinct( \"PROD_CODE_30\" )))\n",
- "#D2G4 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00004\"})))\n",
- "#D2G5 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00005\"})))\n",
- "#D2G6 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00006\"})))\n",
- "#D2G7 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00007\"})))\n",
- "#D2G8 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00008\"})))\n",
- "#D2G9 = pd.DataFrame(list(db.D2.find({\"PROD_CODE_30\":\"G00009\"})))\n",
- "\n",
- "#D3G10 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00010\"})))\n",
- "#D3G11 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00011\"})))\n",
- "#D3G12 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00012\"})))\n",
- "#D3G13 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00013\"})))\n",
- "#D3G14 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00014\"})))\n",
- "#D3G15 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00015\"})))\n",
- "#D3G16 = pd.DataFrame(list(db.D3.find({\"PROD_CODE_30\":\"G00016\"})))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 37,
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "df.to_csv('Data2.csv')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 105,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "3"
- ]
- },
- "execution_count": 105,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "#df1.loc['d':,'A':'C']\n",
- "#df.loc[1:5,'Unnamed: 1':'Unnamed: 3']\n",
- "#Removing the 1st row\n",
- "\n",
- "df.loc[1:5,'name':'x']\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 106,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "3"
- ]
- },
- "execution_count": 106,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "#Changing the column header\n",
- "new_header = df.iloc[0] #grab the first row for the header\n",
- "df = df[1:] #take the data less the header row\n",
- "df.rename(columns = new_header) #set the header row as the df header\n",
- "# Get all the relevant fields\n",
- "\n",
- "\n",
- "\n",
- "#Calculate the Elasticity variable\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "\n",
- "#Modeling \n",
- "\n",
- "\n",
- "\n",
- "#Transformations\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "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.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 0
- }