Welcome to Python! Justin Kiggins Product Manager DataCamp Python - - PowerPoint PPT Presentation

welcome to python
SMART_READER_LITE
LIVE PREVIEW

Welcome to Python! Justin Kiggins Product Manager DataCamp Python - - PowerPoint PPT Presentation

DataCamp Python for MATLAB Users PYTHON FOR MATLAB USERS Welcome to Python! Justin Kiggins Product Manager DataCamp Python for MATLAB Users Prerequisite: Manipulating matrices in MATLAB % Example of manipulating matrices in MATLAB v = [16 5


slide-1
SLIDE 1

DataCamp Python for MATLAB Users

Welcome to Python!

PYTHON FOR MATLAB USERS

Justin Kiggins

Product Manager

slide-2
SLIDE 2

DataCamp Python for MATLAB Users

Prerequisite: Manipulating matrices in MATLAB

% Example of manipulating matrices in MATLAB v = [16 5 9 4 2 11 7 14]; disp(v(5:end)) A = magic(4); disp(A(2:4,1:2)) A(A>12) = 10; disp(A(:,1))

slide-3
SLIDE 3

DataCamp Python for MATLAB Users

Prerequisite: Plotting data in MATLAB

% Example of plotting data in MATLAB figure plot(t,y,'b-') xlabel('Time (s)') ylabel('Sensor A') figure scatter(y1,y2,'go') xlabel('Sensor A') ylabel('Sensor B') figure histogram(y1,[0:0.01:1])

slide-4
SLIDE 4

DataCamp Python for MATLAB Users

Prerequisite: Control flow of MATLAB scripts

% Example of control flow in MATLAB fid = fopen('magic.m','r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) || strncmp(line,'%',1) || ~ischar(line) continue end count = count + 1; end count

slide-5
SLIDE 5

DataCamp Python for MATLAB Users

If you don't know MATLAB...

slide-6
SLIDE 6

DataCamp Python for MATLAB Users

Python does more than Data Science

General purpose programming language Integrate machine learning models into large-scale applications Query data from public APIs Build websites that can handle large traffic volumes

slide-7
SLIDE 7

DataCamp Python for MATLAB Users

Getting started with data types

Integer Float Boolean String

# Integer x = 1 print(x) 1 type(x) <class 'int'> # Float x = 1.0 print(x) 1.0 type(x) <class 'float'>

slide-8
SLIDE 8

DataCamp Python for MATLAB Users

Mathematical operators

Operation Python Operator Addition

+

Subtraction

  • Multiplication

*

Division

/

Exponentiation

** a = 3 + 12 print(a) 15 b = 4 * 5.0 print(b) 20.0

slide-9
SLIDE 9

DataCamp Python for MATLAB Users

Exponentiation in Python

area = πr Warning: Do NOT use the caret operator, ^

2

radius = 5 pi = 3.14 area = pi * (radius ** 2) print(area) 78.5 # This won't take 4 to the second power print(4 ^ 2) # This is the bitwise XOR 6

slide-10
SLIDE 10

DataCamp Python for MATLAB Users

Let's get started!

PYTHON FOR MATLAB USERS

slide-11
SLIDE 11

DataCamp Python for MATLAB Users

Methods and Packages

PYTHON FOR MATLAB USERS

Justin Kiggins

Product Manager

slide-12
SLIDE 12

DataCamp Python for MATLAB Users

Methods are functions attached to variables

Specific to the variable type Accessed with a period

yelling = "WHY ARE YOU YELLING?" whispering = yelling.lower() print(whispering) why are you yelling?

slide-13
SLIDE 13

DataCamp Python for MATLAB Users

The .format() method

n_avocados = 1765 message = "I have {} avocados!".format(n_avocados) print(message) I have 1765 avocados!

slide-14
SLIDE 14

DataCamp Python for MATLAB Users

Python packages

slide-15
SLIDE 15

DataCamp Python for MATLAB Users

Packages have to be imported

Importing part of a package:

import math math.pi 3.141592653589793 math.log(0.9)

  • 0.10536051565782628

from math import log log(0.9)

  • 0.10536051565782628
slide-16
SLIDE 16

DataCamp Python for MATLAB Users

Package aliasing

import datetime as dt birth_date = dt.datetime(1961,8,4) # Import NumPy package with common alias import numpy as np x = np.ndarray([1, 2, 3]) # Import pandas package with common alias import pandas as pd df = pd.DataFrame() # Import Matplotlib pyplot module with common alias import matplotlib.pyplot as plt plt.show() # Import Seaborn package with common alias import seaborn as sns sns.set()

slide-17
SLIDE 17

DataCamp Python for MATLAB Users

Let's explore some useful methods and packages

PYTHON FOR MATLAB USERS

slide-18
SLIDE 18

DataCamp Python for MATLAB Users

Arrays & plotting

PYTHON FOR MATLAB USERS

Justin Kiggins

Product Manager

slide-19
SLIDE 19

DataCamp Python for MATLAB Users

NumPy arrays

Arrays = matrices Arrays can be multidimensional Every element is the same type

slide-20
SLIDE 20

DataCamp Python for MATLAB Users

Indexing into NumPy arrays

Zero-based indexing

print(arr) [[2, 4, 8, 16, 32]] print(arr[2]) 8 print(arr[0]) 2 print(arr[-1]) 32

slide-21
SLIDE 21

DataCamp Python for MATLAB Users

Visualizing data with Matplotlib

slide-22
SLIDE 22

DataCamp Python for MATLAB Users

Using matplotlib

import matplotlib.pyplot as plt # Create a new figure plt.figure() # Plot y as a function of x plt.plot(x, y) # Set the x-label and y-label plt.xlabel('x') plt.ylabel('y') # Be sure to show the plot! plt.show()

slide-23
SLIDE 23

DataCamp Python for MATLAB Users

Let's practice!

PYTHON FOR MATLAB USERS