Microsoft: DAT208x Introduction to Python for Data Science – Module 3

Today I completed Functions and Packages Module 3 of the self paced EdX class Microsoft: DAT208x Introduction to Python for Data Science.

This was almost as much work as module 2 (lists), which is good because it means I’m learning new things.

The short summary of this module is:

Functions – Reusable bits of Python code used a particular task. If you can think of a particular task, there is likely a function for it.

Methods – Subclass of functions tied to a specific type of Python object. Called with a “.” after a variable name. Here’s an example of the difference using the variable “room” with the value “poolhouse”

Function – print(room) – this prints “poolhouse”

Method – room.count(“o”) – This counts the number of times the letter “o” appears in the variable “room” whose value is currently set to “poolhouse”. If we used the command:

print(room.count(“o”)), we would get “3”, the number of times that the letter o appears in poolhouse.

Packages – These are directories of Python functions and methods. Because there are a large number of discipline specific packages for Python, the basic distribution of Python doesn’t have them all. There is a tool called “pip” you can use to download and install packages you need for your work. According to the instructor for this course, three common packages needed for data science are  Numpy, Matplotlib and Scikit-learn. Numpy and Matplotlib have their own separate modules in this class.

Another interesting thing about packages is that installing them into your programming environment isn’t enough. There are one and usually two more things you need to do in your code itself:

  1. Have a line that imports the package (or subpackage, or function)
  2. If you’ve imported the entire package, you’ll need to preface the function with the package name.

So if I want to use the radians function from the math package to determine the number of radians in 12 degrees, I’d need these two lines in my program:

import math

print(math.radians(12))

If you don’t want to put “math.” in front of radians, Python lets you import single functions. So I could execute the radians command as:

from math import radians

print(radians(12))

But doing this method can be confusing to others looking at your code, particularly with longer programs. So I’ll probably import full packages. Not sure what this does to my actual program length. I’ll look into that later.

With this module, I’ve become convinced of the value of downloading Python to my home computer and working on it further. I’ve got other things I need to do today, but will try to start setting up my coding environment this week.

Aside from the constant ads from Datacamp during the lab portion of this course, I’m really liking the course organization of short lectures followed by hands on exercises. It makes me feel like I’m getting stuff done. There should be some way I could start doing training videos in a similar way for database or tech training – though I’m not sure how I’d get the hands-on piece.

Advertisements
This entry was posted in lifelong learning and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s