Category: Python

  • Boolean indexing in NumPy and Pandas: A free e-mail course for aspiring data scientists

    For nearly two years, I have been teaching my introductory course in data science and machine learning to companies around the world. On the one hand, participants are excited by data science, and all of the potential that it has to change our world. On the other hand, there is a lot to learn in…

    Read more

  • 2+2 might be 4, but what is True+True?

    In Python, we know that we can add two integers together: >> 2 + 2 4 And of course, we can add two strings together: >> ‘a’ + ‘b’ ‘ab’ We can even add two lists together: >> [1,2,3] + [4,5,6] [1, 2, 3, 4, 5, 6] But what happens when you add two booleans…

    Read more

  • Python function brain transplants

    What happens when we define a function in Python? The “def” keyword does two things: It creates a function object, and then assigns a variable (our function name) to that function object.  So when I say: def foo():      return “I’m foo!” Python creates a new function object.  Inside of that object, we can see…

    Read more

  • The five-minute guide to setting up a Jupyter notebook server

    Bottom line: To run a Jupyter notebook server your students can log into, install it with pip3 install -U jupyter on a cheap Linux VPS, run jupyter notebook –generate-config, then set open_browser = False and ip = ‘0.0.0.0’ in jupyter_notebook_config.py. Launch it with nohup jupyter notebook and browse to port 8888. Nearly every day, I…

    Read more

  • A short Python class puzzle

    Here’s a short Python puzzle that I use in many of my on-site courses, which I have found to be useful and instructive: Given the following short snippet of Python, which letters will be printed, and in which order? print(“A”) class Person(object):     print(“B”)     def __init__(self, name):         print(“C”)         self.name = name    …

    Read more

  • Data science + machine learning + Python course in Shanghai

    Data science is changing our lives in dramatic ways, and just about every company out there wants to take advantage of the insights that we can gain from analyzing our data — and then making predictions based on that analysis. Python is a leading language (and some would say the leading language) for data scientists.…

    Read more

  • Free download: Cheat sheet for Python data structures

    [thrive_leads id=’1573′] Just about every day of every week, I teach Python. I teach not only in Israel, but also in Europe, China, and the US.  While I do teach newcomers to programming, the overwhelming majority of my students are experienced developers in another language — most often C, C++, Java, or C#. For many…

    Read more

  • The (lack of a) case against Python 3

    A few days ago, well-known author and developer Zed Shaw wrote a blog post, “The Case Against Python 3.”   I have a huge amount of respect for Zed’s work, and his book (Learn Python the Hard Way) is one whose approach is similar to mine — so much so, that I often tell people who…

    Read more

  • Implementing “zip” with list comprehensions

    I love Python’s “zip” function. I’m not sure just what it is about zip that I enjoy, but I have often found it to be quite useful. Before I describe what “zip” does, let me first show you an example: >>> s = ‘abc’ >>> t = (10, 20, 30) >>> zip(s,t) [(‘a’, 10), (‘b’,…

    Read more

  • Fun with floats

    I’m in Shanghai, and before I left to teach this morning, I decided to check the weather.  I knew that it would be hot, but I wanted to double-check that it wasn’t going to rain — a rarity during Israeli summers, but not too unusual in Shanghai. I entered “shanghai weather” into DuckDuckGo, and got…

    Read more