Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Created August 8, 2017 13:41
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 psychemedia/05c3abce7445726d529de090d3c152f6 to your computer and use it in GitHub Desktop.
Save psychemedia/05c3abce7445726d529de090d3c152f6 to your computer and use it in GitHub Desktop.
Preliminary sketch for a course coding bootcamp notebook; note: course materials are generally NOT styled like this!
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TM351 17J Bootcamp\n",
"\n",
"Okay people, step up.\n",
"\n",
"This is programming bootcamp for TM351 17J. The course IS NOT a course about coding or programming, but IT IS a course where you will use code and programming to GET STUFF DONE.\n",
"\n",
"And the bootcamp is NOT here to teach you what you need to know. It's here to TELL YOU what you need to know ALREADY.\n",
"\n",
"The course covers a lot of ground - *a lot* - but the idea is to give you an idea of the terrain and point out some ways to get started.\n",
"\n",
"To become proficient in any part of the course will take way more practice than you have time for over the next few months. So when you start it, try to make mental notes along the way to remind of what you've seen is possible, even if you can't rememeber how to do it. If you do need to do something at a later stage, at work, at play, or during the COURSE ASSESSMENT, you can should then be able to find a starting point for how to do it.\n",
"\n",
"But for now, here are some of the ideas we think you should be familiar with. Because if you aren't, the course will be A WHOLE LOT HARDER than it needs to be."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic Python Programming\n",
"\n",
"That's THREE THINGS:\n",
"\n",
"1. **BASIC** - we'll try to use \"plain Python\" rather than overly concise and cryptic *idiomatic Python*. But that's not to say that sometimes our academics don't get carried away with themselves and very occasionally put in the odd bit of super powerful crypitc voodoo code to make life \"easier\". Code that you *can* start to pick apart, but only if you squint really hard and pick apart piece by piece, looking to see what each step does in part. Which is great if you do, but it can take time. So sometimes you just need to move on, cut-'n'paste, and change the bits that you can recognise. In that meantime, just accept that it works until you have time to try to make sense of it in another life.\n",
"\n",
"2. **PYTHON** - the programming language. You should have done bits of this in the PRE_REQ COURSE. If you haven't, or if you need a reminder, find yourself a Python tutorial on the web and give it a spin. There are bits of revision-style, teaching catchup material in the course, but you need to be able to at least make sense of the basics shown below.\n",
"\n",
"3. **PROGRAMMING** - as distinct from the coding you'll do with Python. By **programming**, we mean getting your thoughts in order and figuring out WHAT YOU WANT TO ACHIEVE, and the SIMPLE STEPS you need to do to achieve it. The Jupyter notebook programming enviroment we use in the course encourages you to write code A LINE AT A TIME. This means you can write each step you need your code to perform as a comment in its own code cell, write the code to do that, then check that it does it.\n",
"\n",
"So what Python do you need to know?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Variables, Lists and dicts\n",
"\n",
"Variables are containers for values. Assign a value to a variable, and the variable name gives you access to the value.\n",
"\n",
"`Lists` are - what do think they are?! LISTS. ORDERED LISTS. You find them in square brackets.\n",
"\n",
"`Dicts` are *dictionaries*, unordered collections of key-value pairs. They're in curly brackers/braces - `{}`. (So are *sets*. GET OVER IT.)\n",
"\n",
"To keep track of what's going on, use SOME TRICKS.\n",
"\n",
"The first trick is: the Jupyter notebook code cell will display any value returned from whatever is in the last line of a code cell.\n",
"\n",
"The second trick is: the `print()` statement, aligned with string formatting. If that doesn't make sense, just use it anyway.\n",
"\n",
"`Lists` and `dict`s let you collect stuff together that you can index into and iterate (loop) through."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'This is the value of the txt variable'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"txt=\"This is the value of the txt variable\"\n",
"txt"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the value of the txt variable\n"
]
}
],
"source": [
"print(txt)"
]
},
{
"cell_type": "code",
"execution_count": 94,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"And this prints out the value of the format values: 1, two, This is the value of the txt variable\n"
]
}
],
"source": [
"print('And this prints out the value of the format values: {}, {}, {}'.format(1,'two',txt))\n",
"#FIGURE IT OUT"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n"
]
}
],
"source": [
"#Lists can be iterated through\n",
"list1=[1,2,3]\n",
"\n",
"for i in list1:\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 3)"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#List items can be indexed, with the index starting at 0, and the last item indexed at -1\n",
"list1[0], list1[-1]\n",
"#FIGURE IT OUT"
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'value_1'"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#dicts let you store and collect together things by name\n",
"dict1={'key1':'value_1',\n",
" 'key2':'value_2',\n",
" 'key3':'value_3'}\n",
"\n",
"dict1['key1']\n",
"#DID YOU SEE WHAT I DID THERE?"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2, 3]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#This can look a bit like voodoo - it's called a LIST COMPREHENSION\n",
"#It creates a list by iterating though something else, possibly with a condition attached... \n",
"#So GO FIGURE\n",
"[i for i in list1 if i>1]\n",
"#There's the odd bit of this voodoo in the course becuase IT'S REALLY HANDY\n",
"#Comprehensions work for dicts too <- HINT CONDITION that you could TRY TO FIGURE OUT HOW TO DO THAT FOR YOURSELF "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here's the value - value_1 - associated with the key *key1*\n",
"Here's the value - value_2 - associated with the key *key2*\n",
"Here's the value - value_3 - associated with the key *key3*\n",
"\n",
"This is a bit more voodoo...: value_2\n"
]
}
],
"source": [
"for key in dict1:\n",
" print(\"Here's the value - {value} - associated with the key *{key}*\".format(key=key, value=dict1[key]))\n",
"\n",
"print(\"\\nThis is a bit more voodoo...: {key2}\".format(**dict1))\n",
"#GET OVER IT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic SQL Querying\n",
"\n",
"That's ANOTHER THREE THINGS.\n",
"\n",
"1. __BASIC__: so not that cryptic; elementary. YOU SHOULD BE ABLE TO FIGURE IT OUT.\n",
"2. __`SQL`__: that's *structured query language*, a *lingua franca* (LOOK IT UP) for database folk that lets them ask their databases questions about the data inside it.\n",
"3. __QUERYING__: asking questions of data. Conditional statements applied to a dataset that return values that match the conditions you specify.\n",
"\n",
"We'll be using all manner of databases, but it helps if you've at least seen what sorts of thing SQL can do."
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#We're going to be using a lot of third party Python packages\n",
"#Most notably the pandas data analysis package\n",
"#You do know how to load a package in, right?!\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col1</th>\n",
" <th>col2</th>\n",
" <th>col3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>a</td>\n",
" <td>P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>b</td>\n",
" <td>P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>c</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>d</td>\n",
" <td>P</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 a P\n",
"1 2 b P\n",
"2 3 c Q\n",
"3 4 d P"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#You'll get used to this voodoo stuff as the course goes on\n",
"df=pd.DataFrame({'col1':[1,2,3,4],\n",
" 'col2':['a','b','c','d'],\n",
" 'col3':['P','P','Q','P']})\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col1</th>\n",
" <th>col2</th>\n",
" <th>col3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>a</td>\n",
" <td>P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>b</td>\n",
" <td>P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>c</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>d</td>\n",
" <td>P</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 a P\n",
"1 2 b P\n",
"2 3 c Q\n",
"3 4 d P"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#You'll also learn how to save and reload things - from local files as well as from web addresses/URLs\n",
"df.to_csv('mydf.csv', index=False)\n",
"df=None\n",
"df=pd.read_csv('mydf.csv')\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#sqlite3 is a disposable, in-memory database\n",
"import sqlite3\n",
"\n",
"con = sqlite3.connect(\"bootcamp.db\")\n",
"#THAT'S JUST HOW IT WORKS - GET OVER IT"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"#We can write to the sqlite3 db from pandas - but you don't necessarily need to know that\n",
"#This is just a step to GET WHERE WE NEED TO BE\n",
"\n",
"#JUST DO IT\n",
"df.to_sql('datatable', con, if_exists='replace', index=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You should be able to read (to MAKE SENSE OF), and write (to be USEFUL), simple queries, such as the ones below. THAT'S WHY WE HAD THE PRE_REQ."
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col1</th>\n",
" <th>col2</th>\n",
" <th>col3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>a</td>\n",
" <td>P</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>b</td>\n",
" <td>P</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 a P\n",
"1 2 b P"
]
},
"execution_count": 97,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q=\"SELECT * FROM datatable LIMIT 2;\"\n",
"\n",
"pd.read_sql_query(q, con)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col1</th>\n",
" <th>col2</th>\n",
" <th>col3</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>3</td>\n",
" <td>c</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4</td>\n",
" <td>d</td>\n",
" <td>P</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col1 col2 col3\n",
"0 3 c Q\n",
"1 4 d P"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q=\"SELECT * FROM datatable WHERE col1 > 2;\"\n",
"\n",
"pd.read_sql_query(q, con)"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>a</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>c</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>d</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col2\n",
"0 a\n",
"1 c\n",
"2 d"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q=\"SELECT col2 FROM datatable WHERE col1 > 2 OR col2='a';\"\n",
"\n",
"pd.read_sql_query(q, con)"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col2</th>\n",
" <th>NewColName</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>d</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>c</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col2 NewColName\n",
"0 d 4\n",
"1 c 3"
]
},
"execution_count": 103,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q=\"SELECT col2, col1 AS NewColName FROM datatable ORDER BY col2 DESC LIMIT 2;\"\n",
"\n",
"pd.read_sql_query(q, con)"
]
},
{
"cell_type": "code",
"execution_count": 101,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>col3</th>\n",
" <th>COUNT(col1)</th>\n",
" <th>Total col1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>P</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Q</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" col3 COUNT(col1) Total col1\n",
"0 P 3 7\n",
"1 Q 1 3"
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"q=\"SELECT col3, COUNT(col1), SUM(col1) AS 'Total col1' FROM datatable GROUP BY col3;\"\n",
"\n",
"pd.read_sql_query(q, con)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic Command-line Stuff\n",
"\n",
"That's the third set of THREE THINGS.\n",
"\n",
"1. __BASIC__: we've BEEN HERE BEFORE.\n",
"2. __COMMAND-LINE__: we're running the course software in a Linux virtual machine. That's a bit more computer than you may be familiar with, and we've done away with the graphical desktop, but DON'T PANIC. You'll get to talk to the computer without the need for crappy menus that you can never find what you want in them anyway.\n",
"3. __STUFF__: cos it's just stuff that you should know if you want to work with computers. Cos it means you know what you're asking the computer to do, rather than trying to guess what the actual COMMAND-LINE instructions that sit behind a lot of menu options is really doing."
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/ajh59/OneDrive - The Open University/TM351/17J\r\n"
]
}
],
"source": [
"#Where am I?\n",
"! pwd"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TM351 17J Bootcamp.ipynb flights.db\r\n",
"TM351 Software Guide-17J.docx mydf.csv\r\n",
"bootcamp.db }bootcamp.db\r\n"
]
}
],
"source": [
"#What else is in this directory?\n",
"! ls"
]
},
{
"cell_type": "code",
"execution_count": 91,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TM351 17J Bootcamp.ipynb flights.db\r\n",
"TM351 Software Guide-17J.docx mydf.csv\r\n",
"bootcamp.db }bootcamp.db\r\n"
]
}
],
"source": [
"#What files are somewhere explicit, like down a path to a particular directory we're interested in?\n",
"! ls \"/Users/ajh59/OneDrive - The Open University/TM351/17J\""
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total 560\r\n",
"-rw-r--r-- 1 ajh59 1182653967 22124 8 Aug 14:01 TM351 17J Bootcamp.ipynb\r\n",
"-rw-r--r--@ 1 ajh59 1182653967 241668 25 Jul 11:59 TM351 Software Guide-17J.docx\r\n",
"-rw-r--r-- 1 ajh59 1182653967 12288 8 Aug 13:53 bootcamp.db\r\n",
"-rw-r--r-- 1 ajh59 1182653967 0 8 Aug 13:37 flights.db\r\n",
"-rw-r--r-- 1 ajh59 1182653967 39 8 Aug 14:03 mydf.csv\r\n",
"-rw-r--r-- 1 ajh59 1182653967 0 8 Aug 13:41 }bootcamp.db\r\n"
]
}
],
"source": [
"#When was that stuff created - and who can see it?\n",
"! ls -l"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 5 mydf.csv\r\n"
]
}
],
"source": [
"#How many lines in the file?\n",
"! wc -l mydf.csv"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"col1,col2,col3\r\n",
"1,a,P\r\n",
"2,b,P\r\n"
]
}
],
"source": [
"#Preview the first few lines of the file\n",
"! head -n 3 mydf.csv"
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2,b,P\r\n",
"3,c,Q\r\n",
"4,d,P\r\n"
]
}
],
"source": [
"#...and the last few\n",
"! tail -n 3 mydf.csv"
]
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2,b,P\r\n",
"3,c,Q\r\n"
]
}
],
"source": [
"#Or the middle few\n",
"! tail -n 3 mydf.csv | head -n2\n",
"#USE YOUR EYES - FIGURE IT OUT"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## OKAY??\n",
"\n",
"That's it... \n",
"\n",
"And if you can't cope with that stuff above - DO THE PRE-REQ COURSE - or go find yourself a tutorial. Or spend some time playing AND GO FIGURE. Cos the learnin's what YOU have to do. THAT'S THE POINT.\n",
"\n",
"And be prepared... Cos when the course starts, there's no brakes..."
]
},
{
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment