jvns/pandas-cookbook — pull request #8 by amygdalama (2014-02-20 19:41:12+00:00)
Title: Added %matplotlib inline, explicit import statements, and fixed a bug in Ch 7

Hey Julia!

I'm mostly done editing your IPython Notebooks so that they can be opened with `ipython notebook` rather than `ipython notebook --pylab inline`. I did this by adding `%matplotlib inline` at the beginning of each notebook that contains plots.

I also added a few more explicit import statements like `import numpy as np` and `import matplotlib.pyplot as plt`. To set the default figure size, I replaced `figsize(15, 5)` with `plt.rcParams['figure.figsize'] = (15, 5)`, which appears to be the way to do it if you aren't importing pylab, but doesn't look very clean :disappointed:

I ran into a few issues while working on this:

1. When loading most datasets, I'm getting the error
```
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/pandas/io/parsers.py:1070: DtypeWarning: Columns (8) have mixed types. Specify dtype option
on import or set low_memory=False.
data = self._reader.read(nrows)
```
I'm not sure if this is just caused by my IPython settings being configured different than yours, or if there's actually an error here.

2. When printing a large dataframe, like `complaints` in chapter 2, IPython is printing the beginning (~60) rows of the dataframe rather than a summary with the columns and non-null values. Same as before, I'm not sure if this is just due to my version of IPython having different settings or if this is a real issue.

3. I found a bug in Chapter 7, when looking at zip codes that are far away (i.e. they don't start with a 0/1 and they aren't null values). The original code is
```
zips = requests['Incident Zip']
# Let's say the zips starting with '0' and '1' are okay, for now. (this isn't actually true -- 13221 is in Syracuse, and why?)
is_close = zips.str.startswith('0') | zips.str.startswith('1')
# There are a bunch of NaNs, but we're not interested in them right now, so we'll say they're True
is_far = ~(is_close.fillna(True).astype(bool))
```
Calling `.fillna(True)` on `is_close` doesn't work because `is_close` is a boolean series. I rewrote the code:
```
zips = requests['Incident Zip']
# Let's say the zips starting with '0' and '1' are okay, for now. (this isn't actually true -- 13221 is in Syracuse, and why?)
is_close = zips.str.startswith('0') | zips.str.startswith('1')
# There are a bunch of NaNs, but we're not interested in them right now, so we'll say they're False
is_far = ~(is_close) & zips.notnull()
```

Would you like me to adjust anything (especially to fix 1 & 2 above)?

Thanks!
Amy