1 of 21

ISA 281

Exam 2 Review

2 of 21

Free Python Resources

This material is outside the course and will not be tested upon.

​

While it's not part of the course, Python for Data Analysis is a great resource for improving your programming skills(plus it’s Free !). It covers some essential Python libraries(Numpy, Pandas and Matplotlib) and I highly recommend reading it. Continuous learning is always better than sprint learning.

  • NumPy
  • Pandas
  • Matplotlib

3 of 21

Feedback from last session

  • Only good things – good thing compared to last year
  • More coding yay!

4 of 21

Agenda

Woohoo!!

5 of 21

How things will work

Slides

Practice Notebook

Slides and practice notebook cover the same topics in order. Make a copy of the exam1_review.ipynb from Canvas/Notion page.

6 of 21

Make a copy of this document

Make a copy of this document

​

Files > Save a copy in Drive

Collab Link available in Canvas/Notion under Exam Review

7 of 21

Disable Code Completions

8 of 21

Chapter 5

9 of 21

Some things before we begin

  • Download the Jupyter notebook from TA Resources in Canvas
  • Don’t suffer in silence. Raise your hand and ask questions wherever you stumble.
  • Ask me to repeat if you don’t understand something. I will be more than happy to help.
  • I will stay back after the session and answer questions.
  • I really want feedback. I want to add the most value to you guys. Any feedback is appreciated - forms under canvas/website.

10 of 21

Functions

  • A function is a block of code which only runs when it is called.
  • You can pass data, known as parameters, into a function.
  • A function can return data(objects) as a result.
  • Compartmentalise and modular.

11 of 21

Default Functions

Default Arguments

10 x 10 = 100

5 x 10 = 50

5 x 5 = 25

12 of 21

Local Variables and Scope

Variable that is assigned a value inside a function

​

Scope: the part of a program in which a variable may be accessed

Scope

Out of Scope

13 of 21

Chapter 6

14 of 21

Opening Files

•open function: used to open a file

–Creates a file object and associates it with a file on the disk

–General format:

– file_object = open(filename, mode)

# Closing the file

file.close()

​

• close function - Closing a file in Python is important to release the resources tied with the file and to ensure that any changes made to it are properly saved.

​

with open("example.txt", "r") as file:

data = file.read()

15 of 21

Exceptions�

The try block lets you test a block of code for errors.

The except block lets you handle the error.

The else block lets you execute code when there is no error.

The finally block lets you execute code, regardless of the result of the try- and except blocks.

16 of 21

Pandas Slicing

df[ start:stop , start:stop ]

row

column

17 of 21

Chapter 7

18 of 21

A note on lists

Nvidia is the most valuable company in the world because their machines do Matrix Multiplications really really well.

Source: 3Blue1Brown

19 of 21

A note on lists

20 of 21

Lists

thislist = ["apple", "banana", "cherry"]

print(thislist)

Lists are used to store multiple items in a single variable.

​

list[start:stop:step]

21 of 21

Feedback