Di v e into P y thon IN TR OD U C TION TO DATA SC IE N C E IN P - - PowerPoint PPT Presentation

di v e into p y thon
SMART_READER_LITE
LIVE PREVIEW

Di v e into P y thon IN TR OD U C TION TO DATA SC IE N C E IN P - - PowerPoint PPT Presentation

Di v e into P y thon IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON Hillar y Green - Lerman Lead Data Scientist , Looker What y o u' ll learn Ho w to w rite and e x ec u te P y thon code w ith DataCamp Ho w to load data from a spreadsheet Ho


slide-1
SLIDE 1

Dive into Python

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON

Hillary Green-Lerman

Lead Data Scientist, Looker

slide-2
SLIDE 2

INTRODUCTION TO DATA SCIENCE IN PYTHON

What you'll learn

How to write and execute Python code with DataCamp How to load data from a spreadsheet How to turn data into beautiful plots

slide-3
SLIDE 3

INTRODUCTION TO DATA SCIENCE IN PYTHON

Solving a mystery with data

slide-4
SLIDE 4

INTRODUCTION TO DATA SCIENCE IN PYTHON

Using the IPython shell

slide-5
SLIDE 5

INTRODUCTION TO DATA SCIENCE IN PYTHON

Using the script editor

slide-6
SLIDE 6

INTRODUCTION TO DATA SCIENCE IN PYTHON

What is a module?

Groups related tools together Makes it easy to know where to look for a particular tool Common examples:

matplotlib pandas scikit-learn scipy nltk

slide-7
SLIDE 7

INTRODUCTION TO DATA SCIENCE IN PYTHON

Importing pandas and matplotlib

import pandas as pd from matplotlib import pyplot as plt # Pandas loads our data df = pd.read_csv('ransom.csv') # Matplotlib plots and displays plt.plot(df.letters, df.frequency) plt.show()

slide-8
SLIDE 8

INTRODUCTION TO DATA SCIENCE IN PYTHON

Importing a module

Importing a Module import pandas Importing a module with an alias import pandas as pd

slide-9
SLIDE 9

Let's practice!

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON

slide-10
SLIDE 10

Creating variables

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON

Hillary Green-Lerman

Lead Data Scientist, Looker

slide-11
SLIDE 11

INTRODUCTION TO DATA SCIENCE IN PYTHON

Filing a missing puppy report

name = "Bayes" height = 24 weight = 75.5

slide-12
SLIDE 12

INTRODUCTION TO DATA SCIENCE IN PYTHON

Rules for variable names

Must start with a leer (usually lowercase) Aer rst leer, can use leers/numbers/underscores No spaces or special characters Case sensitive ( my_var is dierent from MY_VAR )

# Valid Variables bayes_weight b bayes42 # Invalid Variables bayes-height bayes! 42bayes

slide-13
SLIDE 13

INTRODUCTION TO DATA SCIENCE IN PYTHON

Error messages

bayes-height = 3 File "<stdin>", line 1 bayes-height = 3 ^ SyntaxError: can't assign to operator

slide-14
SLIDE 14

INTRODUCTION TO DATA SCIENCE IN PYTHON

Floats and strings

  • at: represents an integer or decimal number

height = 24 weight = 75.5 string: represents text; can contain leers, numbers, spaces, and special characters name = 'Bayes' breed = "Golden Retriever"

slide-15
SLIDE 15

INTRODUCTION TO DATA SCIENCE IN PYTHON

Common string mistakes

Don't forget to use quotes! Without quotes, you'll get a name error.

  • wner = DataCamp

File "<stdin>", line 1, in <module>

  • wner = DataCamp

NameError: name 'DataCamp' is not defined

Use the same type of quotation mark. If you start with a single quote, and end with a double quote, you'll get a syntax error.

fur_color = "blonde' File "<stdin>", line 1 fur_color = "blonde' ^

slide-16
SLIDE 16

INTRODUCTION TO DATA SCIENCE IN PYTHON

Displaying variables

name = "Bayes" height = 24 weight = 75 print(height) 24

slide-17
SLIDE 17

Let's practice!

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON

slide-18
SLIDE 18

What is a function?

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON

Hillary Green-Lerman

Lead Data Scientist, Looker

slide-19
SLIDE 19

INTRODUCTION TO DATA SCIENCE IN PYTHON

A function is an action

slide-20
SLIDE 20

INTRODUCTION TO DATA SCIENCE IN PYTHON

Functions in code

import pandas as pd from matplotlib import pyplot as plt df = pd.read_csv('letter_frequency.csv') plt.plot(df.letter_index, df.frequency, label='Ransom') plt.show()

Functions perform actions:

pd.read_csv() turns a csv le into a table in Python plt.plot() turns data into a line plot plt.show() displays plot in a new window

slide-21
SLIDE 21

INTRODUCTION TO DATA SCIENCE IN PYTHON

slide-22
SLIDE 22

INTRODUCTION TO DATA SCIENCE IN PYTHON

Anatomy of a function: function name

Function Name: Starts with the module that the function "lives" in ( plt ) Followed by the name of the function ( plot ) Function name is always followed by parentheses ()

slide-23
SLIDE 23

INTRODUCTION TO DATA SCIENCE IN PYTHON

Anatomy of a function: positional arguments

Positional Arguments: These are inputs to a function; they tell the function how to do its job Order maers!

slide-24
SLIDE 24

INTRODUCTION TO DATA SCIENCE IN PYTHON

Anatomy of a function: keyword arguments

Keyword Arguments: Must come aer positional arguments Start with the name of the argument ( label ), then an equals sign ( = ) Followed by the argument ( Ransom )

slide-25
SLIDE 25

INTRODUCTION TO DATA SCIENCE IN PYTHON

Common function errors

Missing commas between arguments Missing closed parenthesis

slide-26
SLIDE 26

Let's practice!

IN TR OD U C TION TO DATA SC IE N C E IN P YTH ON