data science tool set python...feb 03, 2019 · 4 tool set python & jupyter notebook...
TRANSCRIPT
DATA SCIENCE TOOL SET
PYTHON
3
AGENDA
0
1
2
3
4
5
6
7
8
Toolsets for Python
Jupyter Python
4
TOOL SET
Python & Jupyter notebookProgramming & Coding
NumPy, SciPy, PandasNumerical Computation
Matplotlib, SeabornData Visualization
Scikit-learnMachine Learning
PYTHON TUTORIALS
The Python Downloadshttps://www.python.org/downloads/
The Python Tutorialhttps://docs.python.org/3/tutorial/
Default editor: IDLE
Anaconda Downloadhttps://www.anaconda.com/distribution/
The Anaconda Tutorialshttps://docs.anaconda.com/anaconda/navigator/tutorials/
PYTHON ANACONDA
PYTHON JUPYTER NOTEBOOK
PYTHON PROGRAMMINGCRASH COURSE
IF-THEN-ELSETest.py
x = int(input("Please enter an integer: "))if x < 0:
x = 0print('Negative changed to zero')
elif x == 0:print('Zero')
elif x == 1:print('Single')
else:print('More')
RECURSIONFib.py
a, b = 0, 1while a < 10:
print(a,end = ' ')a, b = b, a+b
PYTHON PROGRAMMINGCRASH COURSE
FORFor.py
words = ['cat', 'window', 'defenestrate']for w in words:
print(w, len(w))
LISTList.py
combs = []for x in [1,2,3]:
for y in [3,1,4]:if x != y:
combs.append((x, y))
combs
PYTHON PROGRAMMINGCRASH COURSE
KEYWORDS ARGUMENTS 1KeywordsArguments1.py
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):print("-- This parrot wouldn't", action, end=' ')print("if you put", voltage, "volts through it.")print("-- Lovely plumage, the", type)print("-- It's", state, "!")
parrot(1000) # 1 positional argumentparrot(voltage=1000) # 1 keyword argumentparrot(voltage=1000000, action='VOOOOOM') # 2 keyword argumentsparrot(action='VOOOOOM', voltage=1000000) # 2 keyword argumentsparrot('a million', 'bereft of life', 'jump') # 3 positional argumentsparrot('a thousand', state='pushing up the daisies') # 1 positional, 1 keyword
PYTHON PROGRAMMINGCRASH COURSE
KEYWORDS ARGUMENTS 2KeywordsArguments2.py
def cheeseshop(kind, *arguments, **keywords):print("-- Do you have any", kind, "?")print("-- I'm sorry, we're all out of", kind)for arg in arguments:
print(arg)print("-" * 40)for kw in keywords:
print(kw, ":", keywords[kw])
cheeseshop("Limburger", "It's very runny, sir.","It's really very, VERY runny, sir.",shopkeeper="Michael Palin",client="John Cleese",sketch="Cheese Shop Sketch")
PYTHON PROGRAMMINGCRASH COURSE
ARBITRARY ARGUMENTS LISTArbiraryArguments.py
def concat(*args, sep="/"):return sep.join(args)
print(concat("earth", "mars", "venus"))print(concat("earth", "mars", "venus",sep="."))
UNPACKING ARGUMENTS LISTUnpackingArguments.py
def parrot(voltage, state='a stiff', action='voom'):print("-- This parrot wouldn't", action, end=' ')print("if you put", voltage, "volts through it.", end=' ')print("E's", state, "!")
d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}parrot(**d)
PYTHON PROGRAMMINGCRASH COURSE
LAMBDA EXPRESSIONLambdaExpression.py
pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]print(pairs)pairs.sort(key=lambda pair: pair[1])print(pairs)
LISTList1.py
squares = []for x in range(10):
squares.append(x**2)print(squares)
squares = list(map(lambda x: x**2, range(10)))print(squares)
squares = [x**2 for x in range(10)]print(squares)
PYTHON PROGRAMMINGCRASH COURSE
LIST AS STACKListAsStack.py
stack = [3, 4, 5]stack.append(6)stack.append(7)print(stack)print(stack.pop())
LIST AS QUEUEListAsQueue.py
from collections import dequequeue = deque(["Eric", "John", "Michael"])queue.append("Terry")queue.append("Graham")print(queue)print(queue.popleft())
SETSet.py
basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}print(basket)print('orange' in basket)print('crabgrass' in basket)
a = set('abracadabra')b = set('alacazam')print(a)print(b)print(a - b)print(a | b)print(a & b)print(a ^ b)
PYTHON PROGRAMMINGCRASH COURSE
DICTIONARYDictionary.py
tel = {'jack': 4098, 'sape': 4139}tel['guido'] = 4127print(tel)tel['jack']tel['irv'] = 4127print(tel)print(list(tel))print(sorted(tel))print('guido' in tel)
PYTHON PROGRAMMINGCRASH COURSE
DICTIONARY LOOPDictionaryLoop.py
knights = {'gallahad': 'the pure', 'robin': 'the brave'}for k, v in knights.items():
print(k, v)
for i, v in enumerate(['tic', 'tac', 'toe']):print(i, v)
questions = ['name', 'quest', 'favorite color']answers = ['lancelot', 'the holy grail', 'blue']for q, a in zip(questions, answers):
print('What is your {0}? It is {1}.'.format(q, a))
PYTHON PROGRAMMINGCRASH COURSE
CLASSClass.py
class Complex:def __init__(self, realpart, imagpart):
self.r = realpartself.i = imagpart
x = Complex(3.0, -4.5)x.r, x.i
CLASSClass1.py
class MyClass:"""A simple example class"""i = 12345
def f(self):return 'hello world'
x = MyClass()x.f()
x.counter = 1while x.counter < 10:
x.counter = x.counter * 2print(x.counter)del x.counter
xf = x.fprint(xf())
PYTHON PROGRAMMINGCRASH COURSE
CLASSClass2.py
class Dog:kind = 'canine' # class variable shared by all instancesdef __init__(self, name):
self.name = name # instance variable unique to each instance
d = Dog('Fido')e = Dog('Buddy')print(d.kind) # shared by all dogsprint(e.kind) # shared by all dogsprint(d.name) # unique to dprint(e.name) # unique to e