Skip to content

Instantly share code, notes, and snippets.

@ApplyHiTech
Created December 6, 2015 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ApplyHiTech/8933b79b72a617346dd8 to your computer and use it in GitHub Desktop.
Save ApplyHiTech/8933b79b72a617346dd8 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "code",
"execution_count": 54,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib as mlt\n",
"import sklearn\n",
"import random as rd"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"names = [\"Michael Fassbender\", \"Karlie Kloss\", \"Taylor Swift\", \"Justin Bieber\"]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Michael Fassbender\n",
"Karlie Kloss\n",
"Taylor Swift\n"
]
}
],
"source": [
"for i in names: \n",
" if 'l' in i:\n",
"\n",
" print (i)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['michael fassbender', 'karlie kloss', 'taylor swift', 'justin bieber']\n"
]
}
],
"source": [
"i =0 ;\n",
"for b in names:\n",
" names[i]= b.lower()\n",
" i=i+1\n",
"print names"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['karlie kloss', 'taylor swift', 'justin bieber', 'michael fassbender']"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(names,\n",
" key=len\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"#Generate a number between 1-125\n",
"x = rd.randint(1,125)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"91"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"Pandas\n",
"- read in csv file"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#save the data from the csv file to avriable called 'df', short for dataframe. \n",
"#data frame a table/matrix\n",
"df= pd.read_csv(\"sales-funnel.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 62,
"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>Account</th>\n",
" <th>Name</th>\n",
" <th>Rep</th>\n",
" <th>Manager</th>\n",
" <th>Product</th>\n",
" <th>Quantity</th>\n",
" <th>Price</th>\n",
" <th>Status</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>714466</td>\n",
" <td>Trantow-Barrows</td>\n",
" <td>Craig Booker</td>\n",
" <td>Debra Henley</td>\n",
" <td>CPU</td>\n",
" <td>1</td>\n",
" <td>30000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>714466</td>\n",
" <td>Trantow-Barrows</td>\n",
" <td>Craig Booker</td>\n",
" <td>Debra Henley</td>\n",
" <td>Software</td>\n",
" <td>1</td>\n",
" <td>10000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>714466</td>\n",
" <td>Trantow-Barrows</td>\n",
" <td>Craig Booker</td>\n",
" <td>Debra Henley</td>\n",
" <td>Maintenance</td>\n",
" <td>2</td>\n",
" <td>5000</td>\n",
" <td>pending</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>737550</td>\n",
" <td>Fritsch, Russel and Anderson</td>\n",
" <td>Craig Booker</td>\n",
" <td>Debra Henley</td>\n",
" <td>CPU</td>\n",
" <td>1</td>\n",
" <td>35000</td>\n",
" <td>declined</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>146832</td>\n",
" <td>Kiehn-Spinka</td>\n",
" <td>Daniel Hilton</td>\n",
" <td>Debra Henley</td>\n",
" <td>CPU</td>\n",
" <td>2</td>\n",
" <td>65000</td>\n",
" <td>won</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>218895</td>\n",
" <td>Kulas Inc</td>\n",
" <td>Daniel Hilton</td>\n",
" <td>Debra Henley</td>\n",
" <td>CPU</td>\n",
" <td>2</td>\n",
" <td>40000</td>\n",
" <td>pending</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>218895</td>\n",
" <td>Kulas Inc</td>\n",
" <td>Daniel Hilton</td>\n",
" <td>Debra Henley</td>\n",
" <td>Software</td>\n",
" <td>1</td>\n",
" <td>10000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>412290</td>\n",
" <td>Jerde-Hilpert</td>\n",
" <td>John Smith</td>\n",
" <td>Debra Henley</td>\n",
" <td>Maintenance</td>\n",
" <td>2</td>\n",
" <td>5000</td>\n",
" <td>pending</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>740150</td>\n",
" <td>Barton LLC</td>\n",
" <td>John Smith</td>\n",
" <td>Debra Henley</td>\n",
" <td>CPU</td>\n",
" <td>1</td>\n",
" <td>35000</td>\n",
" <td>declined</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>141962</td>\n",
" <td>Herman LLC</td>\n",
" <td>Cedric Moss</td>\n",
" <td>Fred Anderson</td>\n",
" <td>CPU</td>\n",
" <td>2</td>\n",
" <td>65000</td>\n",
" <td>won</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>163416</td>\n",
" <td>Purdy-Kunde</td>\n",
" <td>Cedric Moss</td>\n",
" <td>Fred Anderson</td>\n",
" <td>CPU</td>\n",
" <td>1</td>\n",
" <td>30000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>239344</td>\n",
" <td>Stokes LLC</td>\n",
" <td>Cedric Moss</td>\n",
" <td>Fred Anderson</td>\n",
" <td>Maintenance</td>\n",
" <td>1</td>\n",
" <td>5000</td>\n",
" <td>pending</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>239344</td>\n",
" <td>Stokes LLC</td>\n",
" <td>Cedric Moss</td>\n",
" <td>Fred Anderson</td>\n",
" <td>Software</td>\n",
" <td>1</td>\n",
" <td>10000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>307599</td>\n",
" <td>Kassulke, Ondricka and Metz</td>\n",
" <td>Wendy Yule</td>\n",
" <td>Fred Anderson</td>\n",
" <td>Maintenance</td>\n",
" <td>3</td>\n",
" <td>7000</td>\n",
" <td>won</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>688981</td>\n",
" <td>Keeling LLC</td>\n",
" <td>Wendy Yule</td>\n",
" <td>Fred Anderson</td>\n",
" <td>CPU</td>\n",
" <td>5</td>\n",
" <td>100000</td>\n",
" <td>won</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>729833</td>\n",
" <td>Koepp Ltd</td>\n",
" <td>Wendy Yule</td>\n",
" <td>Fred Anderson</td>\n",
" <td>CPU</td>\n",
" <td>2</td>\n",
" <td>65000</td>\n",
" <td>declined</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>729833</td>\n",
" <td>Koepp Ltd</td>\n",
" <td>Wendy Yule</td>\n",
" <td>Fred Anderson</td>\n",
" <td>Monitor</td>\n",
" <td>2</td>\n",
" <td>5000</td>\n",
" <td>presented</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Account Name Rep Manager \\\n",
"0 714466 Trantow-Barrows Craig Booker Debra Henley \n",
"1 714466 Trantow-Barrows Craig Booker Debra Henley \n",
"2 714466 Trantow-Barrows Craig Booker Debra Henley \n",
"3 737550 Fritsch, Russel and Anderson Craig Booker Debra Henley \n",
"4 146832 Kiehn-Spinka Daniel Hilton Debra Henley \n",
"5 218895 Kulas Inc Daniel Hilton Debra Henley \n",
"6 218895 Kulas Inc Daniel Hilton Debra Henley \n",
"7 412290 Jerde-Hilpert John Smith Debra Henley \n",
"8 740150 Barton LLC John Smith Debra Henley \n",
"9 141962 Herman LLC Cedric Moss Fred Anderson \n",
"10 163416 Purdy-Kunde Cedric Moss Fred Anderson \n",
"11 239344 Stokes LLC Cedric Moss Fred Anderson \n",
"12 239344 Stokes LLC Cedric Moss Fred Anderson \n",
"13 307599 Kassulke, Ondricka and Metz Wendy Yule Fred Anderson \n",
"14 688981 Keeling LLC Wendy Yule Fred Anderson \n",
"15 729833 Koepp Ltd Wendy Yule Fred Anderson \n",
"16 729833 Koepp Ltd Wendy Yule Fred Anderson \n",
"\n",
" Product Quantity Price Status \n",
"0 CPU 1 30000 presented \n",
"1 Software 1 10000 presented \n",
"2 Maintenance 2 5000 pending \n",
"3 CPU 1 35000 declined \n",
"4 CPU 2 65000 won \n",
"5 CPU 2 40000 pending \n",
"6 Software 1 10000 presented \n",
"7 Maintenance 2 5000 pending \n",
"8 CPU 1 35000 declined \n",
"9 CPU 2 65000 won \n",
"10 CPU 1 30000 presented \n",
"11 Maintenance 1 5000 pending \n",
"12 Software 1 10000 presented \n",
"13 Maintenance 3 7000 won \n",
"14 CPU 5 100000 won \n",
"15 CPU 2 65000 declined \n",
"16 Monitor 2 5000 presented "
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"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"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment