When you do mathematical operations on two pandas Series (e.g., `s1 + s2`

), the two Series align on their indexes, but when you compare the same two Series (e.g., `s1 > s2`

), the two Series do not align. Read the rest of this entry »

# Webucator Blog

I just upgraded to Anaconda 2.4, which includes Python 3.5. To update, just run the following code:

conda update conda conda install anaconda=2.4

**Almost** everything seems to have gone smoothly. The exception was that all the markdown headers in my IPython notebooks lost their formatting. They started showing up like this:

Read the rest of this entry »

- Take a Python list:
ls = [1,2,3,4,5]

- Grab a slice:
slice = ls[:2]

- Modify an element in the slice:
slice[1] = 1000

- Check to see if your original list is changed
ls

**[1, 2, 3, 4, 5]** **Result: The original list is unchanged.**

Not so with NumPy arrays and pandas Series Read the rest of this entry »

**Python Coding Challenge**: *You’re in New York City. You walk up to a stranger and ask her what her birthday is. If her birthday is the same as yours, you win. If not, you take her hand and the two of you walk up to another stranger and ask him his birthday. If his birthday is the same as either of yours, you win. If not, one of you takes his hand, and you walk up to another stranger… Keep going until you find someone who has the same birthday as someone else in your group. Use Python to figure out how many tries it will take you.* Read the rest of this entry »

Mark Twain wrote “There are three kinds of lies: lies, damned lies, and statistics.” And statistics indeed can be misleading (intentionally or otherwise).

In baseball, batters who can hit from either side are called switch hitters. They generally hit from the right side against left-handed pitchers and from the left side against right-handed pitchers. Let’s say that you’re a baseball manager and that you need to add a switch hitter to your team. You are considering two different players. Each of the players has had 5,000 major league at bats. Player 1 has a batting average of .296 and Player 2 has a batting average of .315. Let’s say they hit the same number of extra base hits, steal the same number of bases and are equally good fielders. It seems obvious that you should choose Player 2 as he has a significantly higher batting average. Read the rest of this entry »

In IPython Notebook, you can toggle line numbers for an individual cell using the **L** shortcut key:

I needed a function for generating random strings in Python. Here’s what I came up with: Read the rest of this entry »

This is just a convenient listing of all of Python’s `unittest`

Module’s assert methods as of Python 3.5. It is compiled directly from the Python documentation. Read the rest of this entry »

Really small numbers are often expressed in scientific notation. In the video below, I use Python to explain how scientific notation works. Read the rest of this entry »

In this post, I show how to create a simple Simulation class in Python. The purpose of the class is to run a simulation many times and then return stats (e.g., mean, median, etc.) on the results of the simulation.

Let’s start with a simple `Die`

class that has a `roll()`

method that returns an integer between 1 and 6 (inclusive): Read the rest of this entry »