Repository: pandas-dev/pandas
Pull request: DOC: Fixing flake8 errors in cookbook.rst
- [x] closes #23794
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Problem statement:
DOC: Fix format of cookbook.rst
Our documentation should follow the PEP-8 standard, but for historical reasons there are many formats that don't. We should fix them now.

This issue is to fix the format of `doc/source/cookbook.rst`. To find the errors, first is required to install a newer version of `flake8-rst`:
```
conda install -c conda-forge flake8-rst=0.5.0
```

Then, all the errors can be obtained with:
```
$ flake8-rst doc/source/cookbook.rst
doc/source/cookbook.rst:973:42: E231 missing whitespace after ','
doc/source/cookbook.rst:975:32: C408 Unnecessary dict call - rewrite as a literal.
doc/source/cookbook.rst:975:41: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:975:43: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:975:57: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:975:59: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:975:72: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:975:74: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:986:44: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:986:50: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:986:59: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:986:63: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:986:70: E231 missing whitespace after ','
doc/source/cookbook.rst:990:65: E231 missing whitespace after ','
doc/source/cookbook.rst:990:76: E231 missing whitespace after ','
doc/source/cookbook.rst:990:86: E231 missing whitespace after ','
doc/source/cookbook.rst:990:93: E501 line too long (80 > 79 characters)
doc/source/cookbook.rst:1270:9: E305 expected 2 blank lines after class or function definition, found 1
doc/source/cookbook.rst:12:4: F401 'random' imported but unused
doc/source/cookbook.rst:20:31: E225 missing whitespace around operator
doc/source/cookbook.rst:22:4: E402 module level import not at top of file
doc/source/cookbook.rst:22:4: F401 'matplotlib' imported but unused
doc/source/cookbook.rst:60:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:60:15: E203 whitespace before ':'
doc/source/cookbook.rst:60:20: E231 missing whitespace after ','
doc/source/cookbook.rst:60:22: E231 missing whitespace after ','
doc/source/cookbook.rst:60:24: E231 missing whitespace after ','
doc/source/cookbook.rst:60:34: E203 whitespace before ':'
doc/source/cookbook.rst:60:40: E231 missing whitespace after ','
doc/source/cookbook.rst:60:43: E231 missing whitespace after ','
doc/source/cookbook.rst:60:46: E231 missing whitespace after ','
doc/source/cookbook.rst:60:50: E231 missing whitespace after ','
doc/source/cookbook.rst:60:56: E203 whitespace before ':'
doc/source/cookbook.rst:60:63: E231 missing whitespace after ','
doc/source/cookbook.rst:60:66: E231 missing whitespace after ','
doc/source/cookbook.rst:60:70: E231 missing whitespace after ','
doc/source/cookbook.rst:60:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:69:22: E231 missing whitespace after ','
doc/source/cookbook.rst:69:34: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:75:22: E231 missing whitespace after ','
doc/source/cookbook.rst:75:29: E231 missing whitespace after ','
doc/source/cookbook.rst:75:43: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:81:21: E231 missing whitespace after ','
doc/source/cookbook.rst:81:28: E231 missing whitespace after ','
doc/source/cookbook.rst:81:43: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:87:33: E203 whitespace before ':'
doc/source/cookbook.rst:87:53: E203 whitespace before ':'
doc/source/cookbook.rst:87:67: E231 missing whitespace after ','
doc/source/cookbook.rst:87:73: E203 whitespace before ':'
doc/source/cookbook.rst:87:81: E231 missing whitespace after ','
doc/source/cookbook.rst:87:83: E501 line too long (90 > 79 characters)
doc/source/cookbook.rst:88:20: E231 missing whitespace after ','
doc/source/cookbook.rst:96:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:96:15: E203 whitespace before ':'
doc/source/cookbook.rst:96:20: E231 missing whitespace after ','
doc/source/cookbook.rst:96:22: E231 missing whitespace after ','
doc/source/cookbook.rst:96:24: E231 missing whitespace after ','
doc/source/cookbook.rst:96:34: E203 whitespace before ':'
doc/source/cookbook.rst:96:40: E231 missing whitespace after ','
doc/source/cookbook.rst:96:43: E231 missing whitespace after ','
doc/source/cookbook.rst:96:46: E231 missing whitespace after ','
doc/source/cookbook.rst:96:50: E231 missing whitespace after ','
doc/source/cookbook.rst:96:56: E203 whitespace before ':'
doc/source/cookbook.rst:96:63: E231 missing whitespace after ','
doc/source/cookbook.rst:96:66: E231 missing whitespace after ','
doc/source/cookbook.rst:96:70: E231 missing whitespace after ','
doc/source/cookbook.rst:96:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:98:40: E231 missing whitespace after ','
doc/source/cookbook.rst:98:47: E231 missing whitespace after ','
doc/source/cookbook.rst:98:54: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:109:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:109:15: E203 whitespace before ':'
doc/source/cookbook.rst:109:20: E231 missing whitespace after ','
doc/source/cookbook.rst:109:22: E231 missing whitespace after ','
doc/source/cookbook.rst:109:24: E231 missing whitespace after ','
doc/source/cookbook.rst:109:34: E203 whitespace before ':'
doc/source/cookbook.rst:109:40: E231 missing whitespace after ','
doc/source/cookbook.rst:109:43: E231 missing whitespace after ','
doc/source/cookbook.rst:109:46: E231 missing whitespace after ','
doc/source/cookbook.rst:109:50: E231 missing whitespace after ','
doc/source/cookbook.rst:109:56: E203 whitespace before ':'
doc/source/cookbook.rst:109:63: E231 missing whitespace after ','
doc/source/cookbook.rst:109:66: E231 missing whitespace after ','
doc/source/cookbook.rst:109:70: E231 missing whitespace after ','
doc/source/cookbook.rst:109:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:111:27: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:112:27: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:123:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:123:15: E203 whitespace before ':'
doc/source/cookbook.rst:123:20: E231 missing whitespace after ','
doc/source/cookbook.rst:123:22: E231 missing whitespace after ','
doc/source/cookbook.rst:123:24: E231 missing whitespace after ','
doc/source/cookbook.rst:123:34: E203 whitespace before ':'
doc/source/cookbook.rst:123:40: E231 missing whitespace after ','
doc/source/cookbook.rst:123:43: E231 missing whitespace after ','
doc/source/cookbook.rst:123:46: E231 missing whitespace after ','
doc/source/cookbook.rst:123:50: E231 missing whitespace after ','
doc/source/cookbook.rst:123:56: E203 whitespace before ':'
doc/source/cookbook.rst:123:63: E231 missing whitespace after ','
doc/source/cookbook.rst:123:66: E231 missing whitespace after ','
doc/source/cookbook.rst:123:70: E231 missing whitespace after ','
doc/source/cookbook.rst:123:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:129:68: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:135:68: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:141:61: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:149:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:149:15: E203 whitespace before ':'
doc/source/cookbook.rst:149:20: E231 missing whitespace after ','
doc/source/cookbook.rst:149:22: E231 missing whitespace after ','
doc/source/cookbook.rst:149:24: E231 missing whitespace after ','
doc/source/cookbook.rst:149:34: E203 whitespace before ':'
doc/source/cookbook.rst:149:40: E231 missing whitespace after ','
doc/source/cookbook.rst:149:43: E231 missing whitespace after ','
doc/source/cookbook.rst:149:46: E231 missing whitespace after ','
doc/source/cookbook.rst:149:50: E231 missing whitespace after ','
doc/source/cookbook.rst:149:56: E203 whitespace before ':'
doc/source/cookbook.rst:149:63: E231 missing whitespace after ','
doc/source/cookbook.rst:149:66: E231 missing whitespace after ','
doc/source/cookbook.rst:149:70: E231 missing whitespace after ','
doc/source/cookbook.rst:149:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:152:18: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:160:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:160:15: E203 whitespace before ':'
doc/source/cookbook.rst:160:20: E231 missing whitespace after ','
doc/source/cookbook.rst:160:22: E231 missing whitespace after ','
doc/source/cookbook.rst:160:24: E231 missing whitespace after ','
doc/source/cookbook.rst:160:34: E203 whitespace before ':'
doc/source/cookbook.rst:160:40: E231 missing whitespace after ','
doc/source/cookbook.rst:160:43: E231 missing whitespace after ','
doc/source/cookbook.rst:160:46: E231 missing whitespace after ','
doc/source/cookbook.rst:160:50: E231 missing whitespace after ','
doc/source/cookbook.rst:160:56: E203 whitespace before ':'
doc/source/cookbook.rst:160:63: E231 missing whitespace after ','
doc/source/cookbook.rst:160:66: E231 missing whitespace after ','
doc/source/cookbook.rst:160:70: E231 missing whitespace after ','
doc/source/cookbook.rst:160:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:176:21: E231 missing whitespace after ','
doc/source/cookbook.rst:176:27: E231 missing whitespace after ','
doc/source/cookbook.rst:177:39: E231 missing whitespace after ','
doc/source/cookbook.rst:197:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:197:15: E203 whitespace before ':'
doc/source/cookbook.rst:197:20: E231 missing whitespace after ','
doc/source/cookbook.rst:197:22: E231 missing whitespace after ','
doc/source/cookbook.rst:197:24: E231 missing whitespace after ','
doc/source/cookbook.rst:197:34: E203 whitespace before ':'
doc/source/cookbook.rst:197:40: E231 missing whitespace after ','
doc/source/cookbook.rst:197:43: E231 missing whitespace after ','
doc/source/cookbook.rst:197:46: E231 missing whitespace after ','
doc/source/cookbook.rst:197:50: E231 missing whitespace after ','
doc/source/cookbook.rst:197:56: E203 whitespace before ':'
doc/source/cookbook.rst:197:63: E231 missing whitespace after ','
doc/source/cookbook.rst:197:66: E231 missing whitespace after ','
doc/source/cookbook.rst:197:70: E231 missing whitespace after ','
doc/source/cookbook.rst:197:77: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:199:40: E231 missing whitespace after ','
doc/source/cookbook.rst:199:42: E231 missing whitespace after ','
doc/source/cookbook.rst:206:17: E203 whitespace before ':'
doc/source/cookbook.rst:206:22: E231 missing whitespace after ','
doc/source/cookbook.rst:206:24: E231 missing whitespace after ','
doc/source/cookbook.rst:206:26: E231 missing whitespace after ','
doc/source/cookbook.rst:206:36: E203 whitespace before ':'
doc/source/cookbook.rst:206:42: E231 missing whitespace after ','
doc/source/cookbook.rst:206:45: E231 missing whitespace after ','
doc/source/cookbook.rst:206:48: E231 missing whitespace after ','
doc/source/cookbook.rst:206:52: E231 missing whitespace after ','
doc/source/cookbook.rst:206:58: E203 whitespace before ':'
doc/source/cookbook.rst:206:65: E231 missing whitespace after ','
doc/source/cookbook.rst:206:68: E231 missing whitespace after ','
doc/source/cookbook.rst:206:72: E231 missing whitespace after ','
doc/source/cookbook.rst:207:31: E231 missing whitespace after ','
doc/source/cookbook.rst:207:44: E231 missing whitespace after ','
doc/source/cookbook.rst:207:50: E231 missing whitespace after ','
doc/source/cookbook.rst:207:56: E231 missing whitespace after ','
doc/source/cookbook.rst:207:64: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:216:16: E261 at least two spaces before inline comment
doc/source/cookbook.rst:216:17: E262 inline comment should start with '# '
doc/source/cookbook.rst:218:23: E261 at least two spaces before inline comment
doc/source/cookbook.rst:218:24: E262 inline comment should start with '# '
doc/source/cookbook.rst:228:32: E231 missing whitespace after ','
doc/source/cookbook.rst:228:41: E231 missing whitespace after ','
doc/source/cookbook.rst:228:43: E231 missing whitespace after ','
doc/source/cookbook.rst:228:45: E231 missing whitespace after ','
doc/source/cookbook.rst:228:49: E703 statement ends with a semicolon
doc/source/cookbook.rst:228:50: E261 at least two spaces before inline comment
doc/source/cookbook.rst:228:51: E262 inline comment should start with '# '
doc/source/cookbook.rst:230:17: E261 at least two spaces before inline comment
doc/source/cookbook.rst:230:18: E262 inline comment should start with '# '
doc/source/cookbook.rst:232:16: E261 at least two spaces before inline comment
doc/source/cookbook.rst:232:17: E262 inline comment should start with '# '
doc/source/cookbook.rst:240:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:240:15: E203 whitespace before ':'
doc/source/cookbook.rst:240:20: E231 missing whitespace after ','
doc/source/cookbook.rst:240:22: E231 missing whitespace after ','
doc/source/cookbook.rst:240:24: E231 missing whitespace after ','
doc/source/cookbook.rst:240:34: E203 whitespace before ':'
doc/source/cookbook.rst:240:40: E231 missing whitespace after ','
doc/source/cookbook.rst:240:43: E231 missing whitespace after ','
doc/source/cookbook.rst:240:46: E231 missing whitespace after ','
doc/source/cookbook.rst:240:57: E203 whitespace before ':'
doc/source/cookbook.rst:240:64: E231 missing whitespace after ','
doc/source/cookbook.rst:240:67: E231 missing whitespace after ','
doc/source/cookbook.rst:240:71: E231 missing whitespace after ','
doc/source/cookbook.rst:240:78: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:242:42: E231 missing whitespace after ','
doc/source/cookbook.rst:242:44: E231 missing whitespace after ','
doc/source/cookbook.rst:252:34: E231 missing whitespace after ','
doc/source/cookbook.rst:252:46: E231 missing whitespace after ','
doc/source/cookbook.rst:254:15: E231 missing whitespace after ','
doc/source/cookbook.rst:254:19: E231 missing whitespace after ','
doc/source/cookbook.rst:254:23: E231 missing whitespace after ','
doc/source/cookbook.rst:255:83: E501 line too long (107 > 79 characters)
doc/source/cookbook.rst:257:24: E231 missing whitespace after ':'
doc/source/cookbook.rst:257:28: E231 missing whitespace after ','
doc/source/cookbook.rst:257:34: E231 missing whitespace after ':'
doc/source/cookbook.rst:257:38: E231 missing whitespace after ','
doc/source/cookbook.rst:257:44: E231 missing whitespace after ':'
doc/source/cookbook.rst:257:50: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:257:50: E231 missing whitespace after ';'
doc/source/cookbook.rst:259:12: E231 missing whitespace after ','
doc/source/cookbook.rst:259:14: E231 missing whitespace after ','
doc/source/cookbook.rst:259:51: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:259:51: E231 missing whitespace after ';'
doc/source/cookbook.rst:273:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:273:15: E203 whitespace before ':'
doc/source/cookbook.rst:273:20: E231 missing whitespace after ','
doc/source/cookbook.rst:273:22: E231 missing whitespace after ','
doc/source/cookbook.rst:273:24: E231 missing whitespace after ','
doc/source/cookbook.rst:273:34: E203 whitespace before ':'
doc/source/cookbook.rst:273:39: E231 missing whitespace after ','
doc/source/cookbook.rst:273:41: E231 missing whitespace after ','
doc/source/cookbook.rst:273:43: E231 missing whitespace after ','
doc/source/cookbook.rst:273:53: E203 whitespace before ':'
doc/source/cookbook.rst:273:58: E231 missing whitespace after ','
doc/source/cookbook.rst:273:60: E231 missing whitespace after ','
doc/source/cookbook.rst:273:62: E231 missing whitespace after ','
doc/source/cookbook.rst:273:67: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:275:28: E261 at least two spaces before inline comment
doc/source/cookbook.rst:277:19: E203 whitespace before ':'
doc/source/cookbook.rst:277:32: E203 whitespace before ':'
doc/source/cookbook.rst:277:44: E203 whitespace before ':'
doc/source/cookbook.rst:277:56: E202 whitespace before '}'
doc/source/cookbook.rst:279:59: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:279:59: E231 missing whitespace after ';'
doc/source/cookbook.rst:287:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:287:15: E203 whitespace before ':'
doc/source/cookbook.rst:287:20: E231 missing whitespace after ','
doc/source/cookbook.rst:287:22: E231 missing whitespace after ','
doc/source/cookbook.rst:287:24: E231 missing whitespace after ','
doc/source/cookbook.rst:287:26: E231 missing whitespace after ','
doc/source/cookbook.rst:287:28: E231 missing whitespace after ','
doc/source/cookbook.rst:287:30: E231 missing whitespace after ','
doc/source/cookbook.rst:287:32: E231 missing whitespace after ','
doc/source/cookbook.rst:287:42: E203 whitespace before ':'
doc/source/cookbook.rst:287:47: E231 missing whitespace after ','
doc/source/cookbook.rst:287:49: E231 missing whitespace after ','
doc/source/cookbook.rst:287:51: E231 missing whitespace after ','
doc/source/cookbook.rst:287:53: E231 missing whitespace after ','
doc/source/cookbook.rst:287:55: E231 missing whitespace after ','
doc/source/cookbook.rst:287:57: E231 missing whitespace after ','
doc/source/cookbook.rst:287:59: E231 missing whitespace after ','
doc/source/cookbook.rst:287:64: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:315:28: E203 whitespace before ':'
doc/source/cookbook.rst:315:33: E231 missing whitespace after ','
doc/source/cookbook.rst:315:35: E231 missing whitespace after ','
doc/source/cookbook.rst:316:30: E203 whitespace before ':'
doc/source/cookbook.rst:316:37: E231 missing whitespace after ','
doc/source/cookbook.rst:316:41: E231 missing whitespace after ','
doc/source/cookbook.rst:317:30: E203 whitespace before ':'
doc/source/cookbook.rst:317:37: E231 missing whitespace after ','
doc/source/cookbook.rst:317:41: E231 missing whitespace after ','
doc/source/cookbook.rst:318:30: E203 whitespace before ':'
doc/source/cookbook.rst:318:38: E231 missing whitespace after ','
doc/source/cookbook.rst:318:43: E231 missing whitespace after ','
doc/source/cookbook.rst:319:30: E203 whitespace before ':'
doc/source/cookbook.rst:319:38: E231 missing whitespace after ','
doc/source/cookbook.rst:319:43: E231 missing whitespace after ','
doc/source/cookbook.rst:319:51: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:322:28: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:322:28: E231 missing whitespace after ';'
doc/source/cookbook.rst:324:83: E501 line too long (84 > 79 characters)
doc/source/cookbook.rst:324:85: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:324:85: E231 missing whitespace after ';'
doc/source/cookbook.rst:326:35: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:326:35: E231 missing whitespace after ';'
doc/source/cookbook.rst:328:26: E231 missing whitespace after ','
doc/source/cookbook.rst:328:34: E231 missing whitespace after ','
doc/source/cookbook.rst:328:43: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:328:43: E231 missing whitespace after ';'
doc/source/cookbook.rst:338:38: E201 whitespace after '['
doc/source/cookbook.rst:338:41: E231 missing whitespace after ','
doc/source/cookbook.rst:338:58: E231 missing whitespace after ','
doc/source/cookbook.rst:338:62: E231 missing whitespace after ','
doc/source/cookbook.rst:338:81: E231 missing whitespace after ','
doc/source/cookbook.rst:338:83: E501 line too long (84 > 79 characters)
doc/source/cookbook.rst:339:39: E231 missing whitespace after ','
doc/source/cookbook.rst:339:42: E231 missing whitespace after ','
doc/source/cookbook.rst:339:53: E231 missing whitespace after ','
doc/source/cookbook.rst:339:58: E231 missing whitespace after ','
doc/source/cookbook.rst:339:72: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:340:23: E231 missing whitespace after ','
doc/source/cookbook.rst:340:32: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:350:19: E231 missing whitespace after ','
doc/source/cookbook.rst:350:26: E231 missing whitespace after ','
doc/source/cookbook.rst:350:32: E231 missing whitespace after ','
doc/source/cookbook.rst:350:39: E231 missing whitespace after ','
doc/source/cookbook.rst:350:45: E231 missing whitespace after ','
doc/source/cookbook.rst:350:52: E231 missing whitespace after ','
doc/source/cookbook.rst:350:58: E231 missing whitespace after ','
doc/source/cookbook.rst:350:65: E231 missing whitespace after ','
doc/source/cookbook.rst:350:71: E231 missing whitespace after ','
doc/source/cookbook.rst:352:25: E231 missing whitespace after ','
doc/source/cookbook.rst:352:28: E231 missing whitespace after ','
doc/source/cookbook.rst:352:31: E231 missing whitespace after ','
doc/source/cookbook.rst:352:34: E231 missing whitespace after ','
doc/source/cookbook.rst:352:38: E231 missing whitespace after ','
doc/source/cookbook.rst:352:44: E231 missing whitespace after ','
doc/source/cookbook.rst:352:56: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:358:14: E231 missing whitespace after ','
doc/source/cookbook.rst:358:22: E231 missing whitespace after ','
doc/source/cookbook.rst:358:32: E262 inline comment should start with '# '
doc/source/cookbook.rst:358:83: E501 line too long (84 > 79 characters)
doc/source/cookbook.rst:364:15: E231 missing whitespace after ','
doc/source/cookbook.rst:364:23: E231 missing whitespace after ','
doc/source/cookbook.rst:371:41: E231 missing whitespace after ','
doc/source/cookbook.rst:371:49: E231 missing whitespace after ','
doc/source/cookbook.rst:371:59: E231 missing whitespace after ','
doc/source/cookbook.rst:371:67: E231 missing whitespace after ','
doc/source/cookbook.rst:371:74: E231 missing whitespace after ','
doc/source/cookbook.rst:372:43: E231 missing whitespace after ','
doc/source/cookbook.rst:372:51: E231 missing whitespace after ','
doc/source/cookbook.rst:372:56: E231 missing whitespace after ','
doc/source/cookbook.rst:374:42: E231 missing whitespace after ','
doc/source/cookbook.rst:374:59: E231 missing whitespace after ','
doc/source/cookbook.rst:375:43: E261 at least two spaces before inline comment
doc/source/cookbook.rst:375:44: E262 inline comment should start with '# '
doc/source/cookbook.rst:377:15: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:377:17: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:377:19: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:377:22: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:377:25: E228 missing whitespace around modulo operator
doc/source/cookbook.rst:379:26: E231 missing whitespace after ','
doc/source/cookbook.rst:379:31: E231 missing whitespace after ','
doc/source/cookbook.rst:379:37: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:384:15: E231 missing whitespace after ','
doc/source/cookbook.rst:384:23: E231 missing whitespace after ','
doc/source/cookbook.rst:385:23: E231 missing whitespace after ','
doc/source/cookbook.rst:385:32: E231 missing whitespace after ','
doc/source/cookbook.rst:385:40: E231 missing whitespace after ','
doc/source/cookbook.rst:386:15: E231 missing whitespace after ','
doc/source/cookbook.rst:386:23: E231 missing whitespace after ','
doc/source/cookbook.rst:387:15: E231 missing whitespace after ','
doc/source/cookbook.rst:387:23: E231 missing whitespace after ','
doc/source/cookbook.rst:387:28: E231 missing whitespace after ','
doc/source/cookbook.rst:425:39: E231 missing whitespace after ','
doc/source/cookbook.rst:425:83: E501 line too long (114 > 79 characters)
doc/source/cookbook.rst:456:30: E203 whitespace before ':'
doc/source/cookbook.rst:456:59: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:458:4: E265 block comment should start with '# '
doc/source/cookbook.rst:476:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:476:19: E222 multiple spaces after operator
doc/source/cookbook.rst:477:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:478:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:479:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:480:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:480:28: E231 missing whitespace after ','
doc/source/cookbook.rst:480:39: E231 missing whitespace after ','
doc/source/cookbook.rst:491:45: E231 missing whitespace after ','
doc/source/cookbook.rst:493:16: E231 missing whitespace after ','
doc/source/cookbook.rst:494:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:497:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:497:37: E231 missing whitespace after ','
doc/source/cookbook.rst:497:39: E231 missing whitespace after ','
doc/source/cookbook.rst:507:26: E203 whitespace before ':'
doc/source/cookbook.rst:507:46: E203 whitespace before ':'
doc/source/cookbook.rst:538:42: E231 missing whitespace after ','
doc/source/cookbook.rst:538:53: E231 missing whitespace after ','
doc/source/cookbook.rst:539:23: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:539:25: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:539:48: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:539:50: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:542:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:543:10: E111 indentation is not a multiple of four
doc/source/cookbook.rst:544:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:546:17: E203 whitespace before ':'
doc/source/cookbook.rst:546:34: E203 whitespace before ':'
doc/source/cookbook.rst:546:53: E203 whitespace before ':'
doc/source/cookbook.rst:556:52: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:566:7: E121 continuation line under-indented for hanging indent
doc/source/cookbook.rst:568:8: E131 continuation line unaligned for hanging indent
doc/source/cookbook.rst:569:51: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:578:29: E231 missing whitespace after ':'
doc/source/cookbook.rst:578:38: E231 missing whitespace after ','
doc/source/cookbook.rst:578:46: E231 missing whitespace after ','
doc/source/cookbook.rst:578:53: E231 missing whitespace after ','
doc/source/cookbook.rst:578:60: E231 missing whitespace after ','
doc/source/cookbook.rst:579:32: E231 missing whitespace after ':'
doc/source/cookbook.rst:579:40: E231 missing whitespace after ','
doc/source/cookbook.rst:579:46: E231 missing whitespace after ','
doc/source/cookbook.rst:579:53: E231 missing whitespace after ','
doc/source/cookbook.rst:579:60: E231 missing whitespace after ','
doc/source/cookbook.rst:580:27: E231 missing whitespace after ':'
doc/source/cookbook.rst:616:34: E203 whitespace before ':'
doc/source/cookbook.rst:616:41: E231 missing whitespace after ','
doc/source/cookbook.rst:616:45: E231 missing whitespace after ','
doc/source/cookbook.rst:616:49: E231 missing whitespace after ','
doc/source/cookbook.rst:616:53: E231 missing whitespace after ','
doc/source/cookbook.rst:616:57: E231 missing whitespace after ','
doc/source/cookbook.rst:616:61: E231 missing whitespace after ','
doc/source/cookbook.rst:616:65: E231 missing whitespace after ','
doc/source/cookbook.rst:616:69: E231 missing whitespace after ','
doc/source/cookbook.rst:617:34: E203 whitespace before ':'
doc/source/cookbook.rst:619:33: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:619:45: E225 missing whitespace around operator
doc/source/cookbook.rst:619:78: E231 missing whitespace after ','
doc/source/cookbook.rst:619:83: E501 line too long (105 > 79 characters)
doc/source/cookbook.rst:636:38: E203 whitespace before ':'
doc/source/cookbook.rst:636:46: E231 missing whitespace after ','
doc/source/cookbook.rst:636:51: E231 missing whitespace after ','
doc/source/cookbook.rst:636:56: E231 missing whitespace after ','
doc/source/cookbook.rst:636:61: E231 missing whitespace after ','
doc/source/cookbook.rst:636:66: E231 missing whitespace after ','
doc/source/cookbook.rst:636:71: E231 missing whitespace after ','
doc/source/cookbook.rst:637:29: E127 continuation line over-indented for visual indent
doc/source/cookbook.rst:637:35: E203 whitespace before ':'
doc/source/cookbook.rst:637:48: E231 missing whitespace after ','
doc/source/cookbook.rst:637:59: E231 missing whitespace after ','
doc/source/cookbook.rst:637:71: E231 missing whitespace after ','
doc/source/cookbook.rst:637:81: E231 missing whitespace after ','
doc/source/cookbook.rst:637:83: E501 line too long (111 > 79 characters)
doc/source/cookbook.rst:637:92: E231 missing whitespace after ','
doc/source/cookbook.rst:637:103: E231 missing whitespace after ','
doc/source/cookbook.rst:638:36: E203 whitespace before ':'
doc/source/cookbook.rst:638:42: E231 missing whitespace after ','
doc/source/cookbook.rst:638:44: E231 missing whitespace after ','
doc/source/cookbook.rst:638:47: E231 missing whitespace after ','
doc/source/cookbook.rst:638:49: E231 missing whitespace after ','
doc/source/cookbook.rst:638:51: E231 missing whitespace after ','
doc/source/cookbook.rst:638:53: E231 missing whitespace after ','
doc/source/cookbook.rst:639:29: E231 missing whitespace after ','
doc/source/cookbook.rst:639:46: E231 missing whitespace after ','
doc/source/cookbook.rst:639:65: E231 missing whitespace after ','
doc/source/cookbook.rst:639:82: E231 missing whitespace after ','
doc/source/cookbook.rst:639:83: E501 line too long (107 > 79 characters)
doc/source/cookbook.rst:639:97: E231 missing whitespace after ','
doc/source/cookbook.rst:647:16: E231 missing whitespace after ','
doc/source/cookbook.rst:647:19: E231 missing whitespace after ','
doc/source/cookbook.rst:647:22: E231 missing whitespace after ','
doc/source/cookbook.rst:647:25: E231 missing whitespace after ','
doc/source/cookbook.rst:647:28: E231 missing whitespace after ','
doc/source/cookbook.rst:647:31: E231 missing whitespace after ','
doc/source/cookbook.rst:647:34: E231 missing whitespace after ','
doc/source/cookbook.rst:647:37: E231 missing whitespace after ','
doc/source/cookbook.rst:647:40: E231 missing whitespace after ','
doc/source/cookbook.rst:648:22: E201 whitespace after '('
doc/source/cookbook.rst:649:32: E203 whitespace before ':'
doc/source/cookbook.rst:649:83: E501 line too long (82 > 79 characters)
doc/source/cookbook.rst:650:43: E231 missing whitespace after ','
doc/source/cookbook.rst:650:50: E231 missing whitespace after ','
doc/source/cookbook.rst:650:57: E231 missing whitespace after ','
doc/source/cookbook.rst:650:64: E231 missing whitespace after ','
doc/source/cookbook.rst:650:71: E231 missing whitespace after ','
doc/source/cookbook.rst:650:78: E231 missing whitespace after ','
doc/source/cookbook.rst:650:83: E501 line too long (104 > 79 characters)
doc/source/cookbook.rst:650:85: E231 missing whitespace after ','
doc/source/cookbook.rst:650:92: E231 missing whitespace after ','
doc/source/cookbook.rst:650:99: E231 missing whitespace after ','
doc/source/cookbook.rst:651:83: E501 line too long (122 > 79 characters)
doc/source/cookbook.rst:652:46: E231 missing whitespace after ','
doc/source/cookbook.rst:652:52: E231 missing whitespace after ','
doc/source/cookbook.rst:652:58: E231 missing whitespace after ','
doc/source/cookbook.rst:652:64: E231 missing whitespace after ','
doc/source/cookbook.rst:652:69: E231 missing whitespace after ','
doc/source/cookbook.rst:652:75: E231 missing whitespace after ','
doc/source/cookbook.rst:652:81: E231 missing whitespace after ','
doc/source/cookbook.rst:652:83: E501 line too long (97 > 79 characters)
doc/source/cookbook.rst:652:87: E231 missing whitespace after ','
doc/source/cookbook.rst:652:93: E231 missing whitespace after ','
doc/source/cookbook.rst:654:41: E231 missing whitespace after ','
doc/source/cookbook.rst:654:46: E231 missing whitespace after ','
doc/source/cookbook.rst:654:51: E231 missing whitespace after ','
doc/source/cookbook.rst:654:57: E231 missing whitespace after ','
doc/source/cookbook.rst:654:63: E231 missing whitespace after ','
doc/source/cookbook.rst:654:69: E231 missing whitespace after ','
doc/source/cookbook.rst:654:75: E231 missing whitespace after ','
doc/source/cookbook.rst:654:80: E231 missing whitespace after ','
doc/source/cookbook.rst:654:83: E501 line too long (89 > 79 characters)
doc/source/cookbook.rst:654:85: E231 missing whitespace after ','
doc/source/cookbook.rst:658:24: E128 continuation line under-indented for visual indent
doc/source/cookbook.rst:659:24: E128 continuation line under-indented for visual indent
doc/source/cookbook.rst:659:34: E203 whitespace before ':'
doc/source/cookbook.rst:659:45: E203 whitespace before ':'
doc/source/cookbook.rst:660:24: E128 continuation line under-indented for visual indent
doc/source/cookbook.rst:660:31: E203 whitespace before ':'
doc/source/cookbook.rst:660:42: E203 whitespace before ':'
doc/source/cookbook.rst:683:31: E203 whitespace before ':'
doc/source/cookbook.rst:683:37: E231 missing whitespace after ','
doc/source/cookbook.rst:683:39: E231 missing whitespace after ','
doc/source/cookbook.rst:683:41: E231 missing whitespace after ','
doc/source/cookbook.rst:683:45: E231 missing whitespace after ','
doc/source/cookbook.rst:683:50: E231 missing whitespace after ','
doc/source/cookbook.rst:683:55: E231 missing whitespace after ','
doc/source/cookbook.rst:683:59: E231 missing whitespace after ','
doc/source/cookbook.rst:683:62: E231 missing whitespace after ','
doc/source/cookbook.rst:683:72: E203 whitespace before ':'
doc/source/cookbook.rst:683:80: E231 missing whitespace after ','
doc/source/cookbook.rst:683:83: E501 line too long (131 > 79 characters)
doc/source/cookbook.rst:683:84: E231 missing whitespace after ','
doc/source/cookbook.rst:683:89: E231 missing whitespace after ','
doc/source/cookbook.rst:683:95: E231 missing whitespace after ','
doc/source/cookbook.rst:683:101: E231 missing whitespace after ','
doc/source/cookbook.rst:683:111: E231 missing whitespace after ','
doc/source/cookbook.rst:683:122: E231 missing whitespace after ','
doc/source/cookbook.rst:683:127: E231 missing whitespace after ','
doc/source/cookbook.rst:686:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:688:24: C404 Unnecessary list comprehension - rewrite as a dict comprehension.
doc/source/cookbook.rst:688:30: E201 whitespace after '['
doc/source/cookbook.rst:688:35: E231 missing whitespace after ','
doc/source/cookbook.rst:688:73: E231 missing whitespace after ','
doc/source/cookbook.rst:688:83: E501 line too long (94 > 79 characters)
doc/source/cookbook.rst:688:94: E202 whitespace before ']'
doc/source/cookbook.rst:697:47: E231 missing whitespace after ','
doc/source/cookbook.rst:697:50: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:698:54: E231 missing whitespace after ','
doc/source/cookbook.rst:699:34: E231 missing whitespace after ','
doc/source/cookbook.rst:699:40: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:701:14: E231 missing whitespace after ','
doc/source/cookbook.rst:702:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:702:20: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:702:27: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:702:41: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:702:44: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:703:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:703:27: E231 missing whitespace after ','
doc/source/cookbook.rst:705:18: C404 Unnecessary list comprehension - rewrite as a dict comprehension.
doc/source/cookbook.rst:705:24: E201 whitespace after '['
doc/source/cookbook.rst:705:43: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:705:46: E231 missing whitespace after ','
doc/source/cookbook.rst:705:54: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:705:58: E231 missing whitespace after ','
doc/source/cookbook.rst:705:83: E501 line too long (91 > 79 characters)
doc/source/cookbook.rst:705:84: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:705:88: E202 whitespace before ']'
doc/source/cookbook.rst:705:92: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:714:29: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:714:31: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:714:44: E231 missing whitespace after ','
doc/source/cookbook.rst:714:52: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:714:54: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:715:29: E203 whitespace before ':'
doc/source/cookbook.rst:716:30: E203 whitespace before ':'
doc/source/cookbook.rst:717:31: E203 whitespace before ':'
doc/source/cookbook.rst:717:55: E231 missing whitespace after ','
doc/source/cookbook.rst:717:60: E231 missing whitespace after ','
doc/source/cookbook.rst:717:83: E501 line too long (83 > 79 characters)
doc/source/cookbook.rst:717:83: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:719:4: E704 multiple statements on one line (def)
doc/source/cookbook.rst:719:39: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:719:58: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:721:19: E201 whitespace after '['
doc/source/cookbook.rst:721:47: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:721:75: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:721:83: E501 line too long (117 > 79 characters)
doc/source/cookbook.rst:721:109: E226 missing whitespace around arithmetic operator
doc/source/cookbook.rst:721:117: E202 whitespace before ']'
doc/source/cookbook.rst:721:120: E703 statement ends with a semicolon
doc/source/cookbook.rst:809:23: E231 missing whitespace after ','
doc/source/cookbook.rst:809:42: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:816:34: E203 whitespace before ':'
doc/source/cookbook.rst:817:34: E203 whitespace before ':'
doc/source/cookbook.rst:818:36: E203 whitespace before ':'
doc/source/cookbook.rst:819:34: E203 whitespace before ':'
doc/source/cookbook.rst:819:57: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:819:57: E231 missing whitespace after ';'
doc/source/cookbook.rst:823:44: E231 missing whitespace after ','
doc/source/cookbook.rst:823:80: E231 missing whitespace after ','
doc/source/cookbook.rst:823:83: E501 line too long (108 > 79 characters)
doc/source/cookbook.rst:823:90: E231 missing whitespace after ','
doc/source/cookbook.rst:823:105: E231 missing whitespace after ','
doc/source/cookbook.rst:874:9: E126 continuation line over-indented for hanging indent
doc/source/cookbook.rst:954:5: E402 module level import not at top of file
doc/source/cookbook.rst:1035:54: E231 missing whitespace after ','
doc/source/cookbook.rst:1036:13: E128 continuation line under-indented for visual indent
doc/source/cookbook.rst:1141:39: E231 missing whitespace after ','
doc/source/cookbook.rst:1143:18: E231 missing whitespace after ','
doc/source/cookbook.rst:1146:48: C408 Unnecessary dict call - rewrite as a literal.
doc/source/cookbook.rst:1146:54: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1146:56: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1288:5: E221 multiple spaces before operator
doc/source/cookbook.rst:1294:30: E231 missing whitespace after ','
doc/source/cookbook.rst:1294:32: E231 missing whitespace after ','
doc/source/cookbook.rst:1294:34: E231 missing whitespace after ','
doc/source/cookbook.rst:1294:36: E231 missing whitespace after ','
doc/source/cookbook.rst:1298:26: E231 missing whitespace after ','
doc/source/cookbook.rst:1298:28: E231 missing whitespace after ','
doc/source/cookbook.rst:1298:30: E231 missing whitespace after ','
doc/source/cookbook.rst:1298:32: E231 missing whitespace after ','
doc/source/cookbook.rst:1307:24: E201 whitespace after '['
doc/source/cookbook.rst:1307:69: E202 whitespace before ']'
doc/source/cookbook.rst:1309:22: C408 Unnecessary dict call - rewrite as a literal.
doc/source/cookbook.rst:1309:28: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1309:30: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1309:35: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1309:37: E251 unexpected spaces around keyword / parameter equals
doc/source/cookbook.rst:1309:46: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:1311:39: E703 statement ends with a semicolon
doc/source/cookbook.rst:1313:43: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:1324:21: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:1326:17: E702 multiple statements on one line (semicolon)
doc/source/cookbook.rst:1336:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1337:10: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1338:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1343:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1344:10: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1345:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1345:34: E231 missing whitespace after ','
doc/source/cookbook.rst:1349:31: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:40: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:43: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:57: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:63: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:75: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:80: E231 missing whitespace after ','
doc/source/cookbook.rst:1350:83: E501 line too long (83 > 79 characters)
doc/source/cookbook.rst:1352:33: E231 missing whitespace after ','
doc/source/cookbook.rst:1365:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1366:7: E111 indentation is not a multiple of four
doc/source/cookbook.rst:1369:7: E121 continuation line under-indented for hanging indent
```

After fixing this issue, the previous command should not report any error.

Hints from issue discussion:

Commit message: DOC: PEP8 compatibility for cookbook.rst

Patch to review:
diff --git a/doc/source/cookbook.rst b/doc/source/cookbook.rst
index 53468e755a722..76fee27d7a001 100644
--- a/doc/source/cookbook.rst
+++ b/doc/source/cookbook.rst
@@ -9,18 +9,15 @@
    import numpy as np
    from pandas.compat import StringIO
 
-   import random
    import os
    import itertools
    import functools
    import datetime
-
+   import glob
    np.random.seed(123456)
 
-   pd.options.display.max_rows=15
+   pd.options.display.max_rows = 15
 
-   import matplotlib
-   # matplotlib.style.use('default')
 
    np.set_printoptions(precision=4, suppress=True)
 
@@ -56,8 +53,9 @@ These are some neat pandas ``idioms``
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
 if-then...
 **********
@@ -66,36 +64,41 @@ An if-then on one column
 
 .. ipython:: python
 
-   df.loc[df.AAA >= 5,'BBB'] = -1; df
+   df.loc[df.AAA >= 5, 'BBB'] = -1
+   df
 
 An if-then with assignment to 2 columns:
 
 .. ipython:: python
 
-   df.loc[df.AAA >= 5,['BBB','CCC']] = 555; df
+   df.loc[df.AAA >= 5, ['BBB', 'CCC']] = 555
+   df
 
 Add another line with different logic, to do the -else
 
 .. ipython:: python
 
-   df.loc[df.AAA < 5,['BBB','CCC']] = 2000; df
+   df.loc[df.AAA < 5, ['BBB', 'CCC']] = 2000
+   df
 
 Or use pandas where after you've set up a mask
 
 .. ipython:: python
 
-   df_mask = pd.DataFrame({'AAA' : [True] * 4, 'BBB' : [False] * 4,'CCC' : [True,False] * 2})
-   df.where(df_mask,-1000)
+   df_mask = pd.DataFrame({'AAA': [True] * 4, 'BBB': [False] * 4,
+                           'CCC': [True, False] * 2})
+   df.where(df_mask, -1000)
 
 `if-then-else using numpy's where()
 <https://stackoverflow.com/questions/19913659/pandas-conditional-creation-of-a-series-dataframe-column>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
-
-   df['logic'] = np.where(df['AAA'] > 5,'high','low'); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
+   df['logic'] = np.where(df['AAA'] > 5, 'high', 'low')
+   df
 
 Splitting
 *********
@@ -105,11 +108,14 @@ Splitting
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
-   dflow = df[df.AAA <= 5]; dflow
-   dfhigh = df[df.AAA > 5]; dfhigh
+   dflow = df[df.AAA <= 5]
+   dflow
+   dfhigh = df[df.AAA > 5]
+   dfhigh
 
 Building Criteria
 *****************
@@ -119,45 +125,50 @@ Building Criteria
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
 ...and (without assignment returns a Series)
 
 .. ipython:: python
 
-   newseries = df.loc[(df['BBB'] < 25) & (df['CCC'] >= -40), 'AAA']; newseries
+   newseries = df.loc[(df['BBB'] < 25) & (df['CCC'] >= -40), 'AAA']
+   newseries
 
 ...or (without assignment returns a Series)
 
 .. ipython:: python
 
-   newseries = df.loc[(df['BBB'] > 25) | (df['CCC'] >= -40), 'AAA']; newseries
+   newseries = df.loc[(df['BBB'] > 25) | (df['CCC'] >= -40), 'AAA']
+   newseries
 
 ...or (with assignment modifies the DataFrame.)
 
 .. ipython:: python
 
-   df.loc[(df['BBB'] > 25) | (df['CCC'] >= 75), 'AAA'] = 0.1; df
+   df.loc[(df['BBB'] > 25) | (df['CCC'] >= 75), 'AAA'] = 0.1
+   df
 
 `Select rows with data closest to certain value using argsort
 <https://stackoverflow.com/questions/17758023/return-rows-in-a-dataframe-closest-to-a-user-defined-number>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
-
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
    aValue = 43.0
-   df.loc[(df.CCC-aValue).abs().argsort()]
+   df.loc[(df.CCC - aValue).abs().argsort()]
 
 `Dynamically reduce a list of criteria using a binary operators
 <https://stackoverflow.com/questions/21058254/pandas-boolean-operation-in-a-python-list/21058331>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
    Crit1 = df.AAA <= 5.5
    Crit2 = df.BBB == 10.0
@@ -173,8 +184,8 @@ One could hard code:
 
 .. ipython:: python
 
-   CritList = [Crit1,Crit2,Crit3]
-   AllCrit = functools.reduce(lambda x,y: x & y, CritList)
+   CritList = [Crit1, Crit2, Crit3]
+   AllCrit = functools.reduce(lambda x, y: x & y, CritList)
 
    df[AllCrit]
 
@@ -193,18 +204,22 @@ The :ref:`indexing <indexing>` docs.
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
-   df[(df.AAA <= 6) & (df.index.isin([0,2,4]))]
+   df[(df.AAA <= 6) & (df.index.isin([0, 2, 4]))]
 
 `Use loc for label-oriented slicing and iloc positional slicing
 <https://github.com/pandas-dev/pandas/issues/2904>`__
 
 .. ipython:: python
 
-   data = {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}
-   df = pd.DataFrame(data=data,index=['foo','bar','boo','kar']); df
+   data = {'AAA': [4, 5, 6, 7],
+           'BBB': [10, 20, 30, 40],
+           'CCC': [100, 50, -30, -50]}
+   df = pd.DataFrame(data=data, index=['foo', 'bar', 'boo', 'kar'])
+   df
 
 There are 2 explicit slicing methods, with a third general case
 
@@ -213,33 +228,35 @@ There are 2 explicit slicing methods, with a third general case
 3. General (Either slicing style : depends on if the slice contains labels or positions)
 
 .. ipython:: python
-   df.iloc[0:3] #Positional
+   df.iloc[0:3]  # Positional
 
-   df.loc['bar':'kar'] #Label
+   df.loc['bar': 'kar']  # Label
 
    # Generic
    df.iloc[0:3]
-   df.loc['bar':'kar']
+   df.loc['bar': 'kar']
 
 Ambiguity arises when an index consists of integers with a non-zero start or non-unit increment.
 
 .. ipython:: python
 
-   df2 = pd.DataFrame(data=data,index=[1,2,3,4]); #Note index starts at 1.
+   df2 = pd.DataFrame(data=data, index=[1, 2, 3, 4])  # Note index starts at 1.
 
-   df2.iloc[1:3] #Position-oriented
+   df2.iloc[1:3]  # Position-oriented
 
-   df2.loc[1:3] #Label-oriented
+   df2.loc[1:3]  # Label-oriented
 
 `Using inverse operator (~) to take the complement of a mask
 <https://stackoverflow.com/questions/14986510/picking-out-elements-based-on-complement-of-indices-in-python-pandas>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40], 'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7],
+                      'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
-   df[~((df.AAA <= 6) & (df.index.isin([0,2,4])))]
+   df[~((df.AAA <= 6) & (df.index.isin([0, 2, 4])))]
 
 Panels
 ******
@@ -249,14 +266,18 @@ Panels
 
 .. ipython:: python
 
-   rng = pd.date_range('1/1/2013',periods=100,freq='D')
+   rng = pd.date_range('1/1/2013', periods=100, freq='D')
    data = np.random.randn(100, 4)
-   cols = ['A','B','C','D']
-   df1, df2, df3 = pd.DataFrame(data, rng, cols), pd.DataFrame(data, rng, cols), pd.DataFrame(data, rng, cols)
+   cols = ['A', 'B', 'C', 'D']
+   df1 = pd.DataFrame(data, rng, cols)
+   df2 = pd.DataFrame(data, rng, cols)
+   df3 = pd.DataFrame(data, rng, cols)
 
-   pf = pd.Panel({'df1':df1,'df2':df2,'df3':df3});pf
+   pf = pd.Panel({'df1': df1, 'df2': df2, 'df3': df3})
+   pf
 
-   pf.loc[:,:,'F'] = pd.DataFrame(data, rng, cols);pf
+   pf.loc[:, :, 'F'] = pd.DataFrame(data, rng, cols)
+   pf
 
 `Mask a panel by using np.where and then reconstructing the panel with the new masked values
 <https://stackoverflow.com/questions/14650341/boolean-mask-in-pandas-panel>`__
@@ -269,22 +290,26 @@ New Columns
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [1,2,1,3], 'BBB' : [1,1,2,2], 'CCC' : [2,1,3,1]}); df
+   df = pd.DataFrame({'AAA': [1, 2, 1, 3],
+                      'BBB': [1, 1, 2, 2],
+                      'CCC': [2, 1, 3, 1]})
+   df
 
-   source_cols = df.columns # or some subset would work too.
+   source_cols = df.columns   # or some subset would work too.
    new_cols = [str(x) + "_cat" for x in source_cols]
-   categories = {1 : 'Alpha', 2 : 'Beta', 3 : 'Charlie' }
+   categories = {1: 'Alpha', 2: 'Beta', 3: 'Charlie'}
 
-   df[new_cols] = df[source_cols].applymap(categories.get);df
+   df[new_cols] = df[source_cols].applymap(categories.get)
+   df
 
 `Keep other columns when using min() with groupby
 <https://stackoverflow.com/questions/23394476/keep-other-columns-when-using-min-with-groupby>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [1,1,1,2,2,2,3,3], 'BBB' : [2,1,3,4,5,1,2,3]}); df
+   df = pd.DataFrame({'AAA': [1, 1, 1, 2, 2, 2, 3, 3],
+                      'BBB': [2, 1, 3, 4, 5, 1, 2, 3]})
+   df
 
 Method 1 : idxmin() to get the index of the minimums
 
@@ -312,20 +337,26 @@ The :ref:`multindexing <advanced.hierarchical>` docs.
 
 .. ipython:: python
 
-   df = pd.DataFrame({'row' : [0,1,2],
-                      'One_X' : [1.1,1.1,1.1],
-                      'One_Y' : [1.2,1.2,1.2],
-                      'Two_X' : [1.11,1.11,1.11],
-                      'Two_Y' : [1.22,1.22,1.22]}); df
+   df = pd.DataFrame({'row': [0, 1, 2],
+                      'One_X': [1.1, 1.1, 1.1],
+                      'One_Y': [1.2, 1.2, 1.2],
+                      'Two_X': [1.11, 1.11, 1.11],
+                      'Two_Y': [1.22, 1.22, 1.22]})
+   df
 
    # As Labelled Index
-   df = df.set_index('row');df
+   df = df.set_index('row')
+   df
    # With Hierarchical Columns
-   df.columns = pd.MultiIndex.from_tuples([tuple(c.split('_')) for c in df.columns]);df
+   df.columns = pd.MultiIndex.from_tuples([tuple(c.split('_'))
+                                           for c in df.columns])
+   df
    # Now stack & Reset
-   df = df.stack(0).reset_index(1);df
+   df = df.stack(0).reset_index(1)
+   df
    # And fix the labels (Notice the label 'level_1' got added automatically)
-   df.columns = ['Sample','All_X','All_Y'];df
+   df.columns = ['Sample', 'All_X', 'All_Y']
+   df
 
 Arithmetic
 **********
@@ -335,9 +366,12 @@ Arithmetic
 
 .. ipython:: python
 
-   cols = pd.MultiIndex.from_tuples([ (x,y) for x in ['A','B','C'] for y in ['O','I']])
-   df = pd.DataFrame(np.random.randn(2,6),index=['n','m'],columns=cols); df
-   df = df.div(df['C'],level=1); df
+   cols = pd.MultiIndex.from_tuples([(x, y) for x in ['A', 'B', 'C']
+                                     for y in ['O', 'I']])
+   df = pd.DataFrame(np.random.randn(2, 6), index=['n', 'm'], columns=cols)
+   df
+   df = df.div(df['C'], level=1)
+   df
 
 Slicing
 *******
@@ -347,44 +381,49 @@ Slicing
 
 .. ipython:: python
 
-   coords = [('AA','one'),('AA','six'),('BB','one'),('BB','two'),('BB','six')]
+   coords = [('AA', 'one'), ('AA', 'six'), ('BB', 'one'), ('BB', 'two'),
+             ('BB', 'six')]
    index = pd.MultiIndex.from_tuples(coords)
-   df = pd.DataFrame([11,22,33,44,55],index,['MyData']); df
+   df = pd.DataFrame([11, 22, 33, 44, 55], index, ['MyData'])
+   df
 
 To take the cross section of the 1st level and 1st axis the index:
 
 .. ipython:: python
 
-   df.xs('BB',level=0,axis=0)  #Note : level and axis are optional, and default to zero
+   # Note : level and axis are optional, and default to zero
+   df.xs('BB', level=0, axis=0)
 
 ...and now the 2nd level of the 1st axis.
 
 .. ipython:: python
 
-   df.xs('six',level=1,axis=0)
+   df.xs('six', level=1, axis=0)
 
 `Slicing a MultiIndex with xs, method #2
 <https://stackoverflow.com/questions/14964493/multiindex-based-indexing-in-pandas>`__
 
 .. ipython:: python
 
-   index = list(itertools.product(['Ada','Quinn','Violet'],['Comp','Math','Sci']))
-   headr = list(itertools.product(['Exams','Labs'],['I','II']))
+   index = list(itertools.product(['Ada', 'Quinn', 'Violet'],
+                                  ['Comp', 'Math', 'Sci']))
+   headr = list(itertools.product(['Exams', 'Labs'], ['I', 'II']))
 
-   indx = pd.MultiIndex.from_tuples(index,names=['Student','Course'])
-   cols = pd.MultiIndex.from_tuples(headr) #Notice these are un-named
+   indx = pd.MultiIndex.from_tuples(index, names=['Student', 'Course'])
+   cols = pd.MultiIndex.from_tuples(headr)   # Notice these are un-named
 
-   data = [[70+x+y+(x*y)%3 for x in range(4)] for y in range(9)]
+   data = [[70 + x + y + (x * y) % 3 for x in range(4)] for y in range(9)]
 
-   df = pd.DataFrame(data,indx,cols); df
+   df = pd.DataFrame(data, indx, cols)
+   df
 
    All = slice(None)
 
    df.loc['Violet']
-   df.loc[(All,'Math'),All]
-   df.loc[(slice('Ada','Quinn'),'Math'),All]
-   df.loc[(All,'Math'),('Exams')]
-   df.loc[(All,'Math'),(All,'II')]
+   df.loc[(All, 'Math'), All]
+   df.loc[(slice('Ada', 'Quinn'), 'Math'), All]
+   df.loc[(All, 'Math'), ('Exams')]
+   df.loc[(All, 'Math'), (All, 'II')]
 
 `Setting portions of a MultiIndex with xs
 <https://stackoverflow.com/questions/19319432/pandas-selecting-a-lower-level-in-a-dataframe-to-do-a-ffill>`__
@@ -422,7 +461,9 @@ Fill forward a reversed timeseries
 
 .. ipython:: python
 
-   df = pd.DataFrame(np.random.randn(6,1), index=pd.date_range('2013-08-01', periods=6, freq='B'), columns=list('A'))
+   df = pd.DataFrame(np.random.randn(6, 1),
+                     index=pd.date_range('2013-08-01', periods=6, freq='B'),
+                     columns=list('A'))
    df.loc[df.index[3], 'A'] = np.nan
    df
    df.reindex(df.index[::-1]).ffill()
@@ -453,9 +494,10 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
    df = pd.DataFrame({'animal': 'cat dog cat fish dog cat cat'.split(),
                       'size': list('SSMMMLL'),
                       'weight': [8, 10, 11, 1, 20, 12, 12],
-                      'adult' : [False] * 5 + [True] * 2}); df
+                      'adult': [False] * 5 + [True] * 2})
+   df
 
-   #List the size of the animals with the highest weight.
+   # List the size of the animals with the highest weight.
    df.groupby('animal').apply(lambda subf: subf['size'][subf['weight'].idxmax()])
 
 `Using get_group
@@ -473,11 +515,12 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 .. ipython:: python
 
    def GrowUp(x):
-      avg_weight =  sum(x[x['size'] == 'S'].weight * 1.5)
-      avg_weight += sum(x[x['size'] == 'M'].weight * 1.25)
-      avg_weight += sum(x[x['size'] == 'L'].weight)
-      avg_weight /= len(x)
-      return pd.Series(['L',avg_weight,True], index=['size', 'weight', 'adult'])
+       avg_weight = sum(x[x['size'] == 'S'].weight * 1.5)
+       avg_weight += sum(x[x['size'] == 'M'].weight * 1.25)
+       avg_weight += sum(x[x['size'] == 'L'].weight)
+       avg_weight /= len(x)
+       return pd.Series(['L', avg_weight, True],
+                        index=['size', 'weight', 'adult'])
 
    expected_df = gb.apply(GrowUp)
 
@@ -488,13 +531,13 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   S = pd.Series([i / 100.0 for i in range(1,11)])
+   S = pd.Series([i / 100.0 for i in range(1, 11)])
 
-   def CumRet(x,y):
-      return x * (1 + y)
+   def CumRet(x, y):
+       return x * (1 + y)
 
    def Red(x):
-      return functools.reduce(CumRet,x,1.0)
+       return functools.reduce(CumRet, x, 1.0)
 
    S.expanding().apply(Red, raw=True)
 
@@ -504,7 +547,7 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   df = pd.DataFrame({'A' : [1, 1, 2, 2], 'B' : [1, -1, 1, 2]})
+   df = pd.DataFrame({'A': [1, 1, 2, 2], 'B': [1, -1, 1, 2]})
    gb = df.groupby('A')
 
    def replace(g):
@@ -535,15 +578,15 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   rng = pd.date_range(start="2014-10-07",periods=10,freq='2min')
-   ts = pd.Series(data = list(range(10)), index = rng)
+   rng = pd.date_range(start="2014-10-07", periods=10, freq='2min')
+   ts = pd.Series(data=list(range(10)), index=rng)
 
    def MyCust(x):
-      if len(x) > 2:
-         return x[1] * 1.234
-      return pd.NaT
+       if len(x) > 2:
+           return x[1] * 1.234
+       return pd.NaT
 
-   mhc = {'Mean' : np.mean, 'Max' : np.max, 'Custom' : MyCust}
+   mhc = {'Mean': np.mean, 'Max': np.max, 'Custom': MyCust}
    ts.resample("5min").apply(mhc)
    ts
 
@@ -553,7 +596,8 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 .. ipython:: python
 
    df = pd.DataFrame({'Color': 'Red Red Red Blue'.split(),
-                      'Value': [100, 150, 50, 50]}); df
+                      'Value': [100, 150, 50, 50]})
+   df
    df['Counts'] = df.groupby(['Color']).transform(len)
    df
 
@@ -562,11 +606,12 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-      {u'line_race': [10, 10, 8, 10, 10, 8],
-       u'beyer': [99, 102, 103, 103, 88, 100]},
-       index=[u'Last Gunfighter', u'Last Gunfighter', u'Last Gunfighter',
-              u'Paynter', u'Paynter', u'Paynter']); df
+   df = pd.DataFrame({u'line_race': [10, 10, 8, 10, 10, 8],
+                      u'beyer': [99, 102, 103, 103, 88, 100]},
+                     index=[u'Last Gunfighter', u'Last Gunfighter',
+                            u'Last Gunfighter', u'Paynter', u'Paynter',
+                            u'Paynter'])
+   df
    df['beyer_shifted'] = df.groupby(level=0)['beyer'].shift(1)
    df
 
@@ -575,9 +620,9 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   df = pd.DataFrame({'host':['other','other','that','this','this'],
-                      'service':['mail','web','mail','mail','web'],
-                      'no':[1, 2, 1, 2, 1]}).set_index(['host', 'service'])
+   df = pd.DataFrame({'host': ['other', 'other', 'that', 'this', 'this'],
+                      'service': ['mail', 'web', 'mail', 'mail', 'web'],
+                      'no': [1, 2, 1, 2, 1]}).set_index(['host', 'service'])
    mask = df.groupby(level=0).agg('idxmax')
    df_count = df.loc[mask['no']].reset_index()
    df_count
@@ -613,10 +658,12 @@ Create a list of dataframes, split using a delineation based on logic included i
 
 .. ipython:: python
 
-   df = pd.DataFrame(data={'Case' : ['A','A','A','B','A','A','B','A','A'],
-                           'Data' : np.random.randn(9)})
+   df = pd.DataFrame(data={'Case': ['A', 'A', 'A', 'B', 'A', 'A', 'B', 'A',
+                                    'A'],
+                           'Data': np.random.randn(9)})
 
-   dfs = list(zip(*df.groupby((1*(df['Case']=='B')).cumsum().rolling(window=3,min_periods=1).median())))[-1]
+   dfs = list(zip(*df.groupby((1 * (df['Case'] == 'B')).cumsum()
+                  .rolling(window=3, min_periods=1).median())))[-1]
 
    dfs[0]
    dfs[1]
@@ -633,10 +680,13 @@ The :ref:`Pivot <reshaping.pivot>` docs.
 
 .. ipython:: python
 
-   df = pd.DataFrame(data={'Province' : ['ON','QC','BC','AL','AL','MN','ON'],
-                            'City' : ['Toronto','Montreal','Vancouver','Calgary','Edmonton','Winnipeg','Windsor'],
-                            'Sales' : [13,6,16,8,4,3,1]})
-   table = pd.pivot_table(df,values=['Sales'],index=['Province'],columns=['City'],aggfunc=np.sum,margins=True)
+   df = pd.DataFrame(data={'Province': ['ON', 'QC', 'BC', 'AL', 'AL', 'MN', 'ON'],
+                           'City': ['Toronto', 'Montreal', 'Vancouver',
+                                    'Calgary', 'Edmonton', 'Winnipeg',
+                                    'Windsor'],
+                           'Sales': [13, 6, 16, 8, 4, 3, 1]})
+   table = pd.pivot_table(df, values=['Sales'], index=['Province'],
+                          columns=['City'], aggfunc=np.sum, margins=True)
    table.stack('City')
 
 `Frequency table like plyr in R
@@ -644,20 +694,26 @@ The :ref:`Pivot <reshaping.pivot>` docs.
 
 .. ipython:: python
 
-   grades = [48,99,75,80,42,80,72,68,36,78]
-   df = pd.DataFrame( {'ID': ["x%d" % r for r in range(10)],
-                       'Gender' : ['F', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'M', 'M'],
-                       'ExamYear': ['2007','2007','2007','2008','2008','2008','2008','2009','2009','2009'],
-                       'Class': ['algebra', 'stats', 'bio', 'algebra', 'algebra', 'stats', 'stats', 'algebra', 'bio', 'bio'],
-                       'Participated': ['yes','yes','yes','yes','no','yes','yes','yes','yes','yes'],
-                       'Passed': ['yes' if x > 50 else 'no' for x in grades],
-                       'Employed': [True,True,True,False,False,False,False,True,True,False],
-                       'Grade': grades})
+   grades = [48, 99, 75, 80, 42, 80, 72, 68, 36, 78]
+   df = pd.DataFrame({'ID': ["x%d" % r for r in range(10)],
+                      'Gender': ['F', 'M', 'F', 'M', 'F',
+                                 'M', 'F', 'M', 'M', 'M'],
+                      'ExamYear': ['2007', '2007', '2007', '2008', '2008',
+                                   '2008', '2008', '2009', '2009', '2009'],
+                      'Class': ['algebra', 'stats', 'bio', 'algebra',
+                                'algebra', 'stats', 'stats', 'algebra',
+                                'bio', 'bio'],
+                      'Participated': ['yes', 'yes', 'yes', 'yes', 'no',
+                                       'yes', 'yes', 'yes', 'yes', 'yes'],
+                      'Passed': ['yes' if x > 50 else 'no' for x in grades],
+                      'Employed': [True, True, True, False,
+                                   False, False, False, True, True, False],
+                      'Grade': grades})
 
    df.groupby('ExamYear').agg({'Participated': lambda x: x.value_counts()['yes'],
-                       'Passed': lambda x: sum(x == 'yes'),
-                       'Employed' : lambda x : sum(x),
-                       'Grade' : lambda x : sum(x) / len(x)})
+                               'Passed': lambda x: sum(x == 'yes'),
+                               'Employed': lambda x: sum(x),
+                               'Grade': lambda x: sum(x) / len(x)})
 
 `Plot pandas DataFrame with year over year data
 <http://stackoverflow.com/questions/30379789/plot-pandas-data-frame-with-year-over-year-data>`__
@@ -680,12 +736,16 @@ Apply
 
 .. ipython:: python
 
-   df = pd.DataFrame(data={'A' : [[2,4,8,16],[100,200],[10,20,30]], 'B' : [['a','b','c'],['jj','kk'],['ccc']]},index=['I','II','III'])
+   df = pd.DataFrame(data={'A': [[2, 4, 8, 16], [100, 200], [10, 20, 30]],
+                           'B': [['a', 'b', 'c'], ['jj', 'kk'], ['ccc']]},
+                     index=['I', 'II', 'III'])
 
    def SeriesFromSubList(aList):
-      return pd.Series(aList)
+       return pd.Series(aList)
 
-   df_orgz = pd.concat(dict([ (ind,row.apply(SeriesFromSubList)) for ind,row in df.iterrows() ]))
+   df_orgz = pd.concat(dict([(ind, row.apply(SeriesFromSubList))
+                             for ind, row in df.iterrows()]))
+   df_orgz
 
 `Rolling Apply with a DataFrame returning a Series
 <http://stackoverflow.com/questions/19121854/using-rolling-apply-on-a-dataframe-object>`__
@@ -694,15 +754,18 @@ Rolling Apply to multiple columns where function calculates a Series before a Sc
 
 .. ipython:: python
 
-   df = pd.DataFrame(data=np.random.randn(2000,2)/10000,
-                     index=pd.date_range('2001-01-01',periods=2000),
-                     columns=['A','B']); df
+   df = pd.DataFrame(data=np.random.randn(2000, 2) / 10000,
+                     index=pd.date_range('2001-01-01', periods=2000),
+                     columns=['A', 'B'])
+   df
 
-   def gm(aDF,Const):
-      v = ((((aDF.A+aDF.B)+1).cumprod())-1)*Const
-      return (aDF.index[0],v.iloc[-1])
+   def gm(aDF, Const):
+       v = ((((aDF.A + aDF.B) + 1).cumprod()) - 1) * Const
+       return (aDF.index[0], v.iloc[-1])
 
-   S = pd.Series(dict([ gm(df.iloc[i:min(i+51,len(df)-1)],5) for i in range(len(df)-50) ])); S
+   S = pd.Series(dict([gm(df.iloc[i:min(i + 51, len(df) - 1)], 5)
+                       for i in range(len(df) - 50)]))
+   S
 
 `Rolling apply with a DataFrame returning a Scalar
 <http://stackoverflow.com/questions/21040766/python-pandas-rolling-apply-two-column-input-into-function/21045831#21045831>`__
@@ -711,14 +774,20 @@ Rolling Apply to multiple columns where function returns a Scalar (Volume Weight
 
 .. ipython:: python
 
-   rng = pd.date_range(start = '2014-01-01',periods = 100)
-   df = pd.DataFrame({'Open' : np.random.randn(len(rng)),
-                      'Close' : np.random.randn(len(rng)),
-                      'Volume' : np.random.randint(100,2000,len(rng))}, index=rng); df
+   rng = pd.date_range(start='2014-01-01', periods=100)
+   df = pd.DataFrame({'Open': np.random.randn(len(rng)),
+                      'Close': np.random.randn(len(rng)),
+                      'Volume': np.random.randint(100, 2000, len(rng))},
+                     index=rng)
+   df
+
+   def vwap(bars):
+       return ((bars.Close * bars.Volume).sum() / bars.Volume.sum())
 
-   def vwap(bars): return ((bars.Close*bars.Volume).sum()/bars.Volume.sum())
    window = 5
-   s = pd.concat([ (pd.Series(vwap(df.iloc[i:i+window]), index=[df.index[i+window]])) for i in range(len(df)-window) ]);
+   s = pd.concat([(pd.Series(vwap(df.iloc[i:i + window]),
+                   index=[df.index[i + window]]))
+                  for i in range(len(df) - window)])
    s.round(2)
 
 Timeseries
@@ -806,21 +875,25 @@ Depending on df construction, ``ignore_index`` may be needed
 
 .. ipython:: python
 
-   df = df1.append(df2,ignore_index=True); df
+   df = df1.append(df2, ignore_index=True)
+   df
 
 `Self Join of a DataFrame
 <https://github.com/pandas-dev/pandas/issues/2996>`__
 
 .. ipython:: python
 
-   df = pd.DataFrame(data={'Area' : ['A'] * 5 + ['C'] * 2,
-                           'Bins' : [110] * 2 + [160] * 3 + [40] * 2,
-                           'Test_0' : [0, 1, 0, 1, 2, 0, 1],
-                           'Data' : np.random.randn(7)});df
+   df = pd.DataFrame(data={'Area': ['A'] * 5 + ['C'] * 2,
+                           'Bins': [110] * 2 + [160] * 3 + [40] * 2,
+                           'Test_0': [0, 1, 0, 1, 2, 0, 1],
+                           'Data': np.random.randn(7)})
+   df
 
    df['Test_1'] = df['Test_0'] - 1
 
-   pd.merge(df, df, left_on=['Bins', 'Area','Test_0'], right_on=['Bins', 'Area','Test_1'],suffixes=('_L','_R'))
+   pd.merge(df, df, left_on=['Bins', 'Area', 'Test_0'],
+            right_on=['Bins', 'Area', 'Test_1'],
+            suffixes=('_L', '_R'))
 
 `How to set the index and join
 <http://stackoverflow.com/questions/14341805/pandas-merge-pd-merge-how-to-set-the-index-and-join>`__
@@ -871,8 +944,8 @@ The :ref:`Plotting <visualization>` docs.
 .. ipython:: python
 
    df = pd.DataFrame(
-        {u'stratifying_var': np.random.uniform(0, 100, 20),
-         u'price': np.random.normal(100, 5, 20)})
+       {u'stratifying_var': np.random.uniform(0, 100, 20),
+        u'price': np.random.normal(100, 5, 20)})
 
    df[u'quartiles'] = pd.qcut(
        df[u'stratifying_var'],
@@ -951,7 +1024,6 @@ You can use the same approach to read all files matching a pattern.  Here is an
 
 .. ipython:: python
 
-    import glob
     files = glob.glob('file_*.csv')
     result = pd.concat([pd.read_csv(f) for f in files], ignore_index=True)
 
@@ -968,38 +1040,19 @@ Parsing date components in multi-columns
 
 Parsing date components in multi-columns is faster with a format
 
-.. code-block:: ipython
-
-    In [30]: i = pd.date_range('20000101',periods=10000)
-
-    In [31]: df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
-
-    In [32]: df.head()
-    Out[32]:
-       day  month  year
-    0    1      1  2000
-    1    2      1  2000
-    2    3      1  2000
-    3    4      1  2000
-    4    5      1  2000
-
-    In [33]: %timeit pd.to_datetime(df.year*10000+df.month*100+df.day,format='%Y%m%d')
-    100 loops, best of 3: 7.08 ms per loop
-
-    # simulate combinging into a string, then parsing
-    In [34]: ds = df.apply(lambda x: "%04d%02d%02d" % (x['year'],x['month'],x['day']),axis=1)
+.. ipython:: python
+    :suppress:
 
-    In [35]: ds.head()
-    Out[35]:
-    0    20000101
-    1    20000102
-    2    20000103
-    3    20000104
-    4    20000105
-    dtype: object
+    i = pd.date_range('20000101', periods=10000)
+    df = pd.DataFrame({'year': i.year, 'month': i.month, 'day': i.day})
+    df.head()
+    %timeit pd.to_datetime(df.year * 10000 + df.month * 100 + df.day,
+                   format='%Y%m%d')
+    ds = df.apply(lambda x: "%04d%02d%02d" % (x['year'],
+                                              x['month'], x['day']), axis=1)
 
-    In [36]: %timeit pd.to_datetime(ds)
-    1 loops, best of 3: 488 ms per loop
+    ds.head()
+    %timeit pd.to_datetime(ds)
 
 Skip row between header and data
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1032,8 +1085,8 @@ Option 1: pass rows explicitly to skip rows
 
 .. ipython:: python
 
-    pd.read_csv(StringIO(data), sep=';', skiprows=[11,12],
-            index_col=0, parse_dates=True, header=10)
+    pd.read_csv(StringIO(data), sep=';', skiprows=[11, 12],
+                index_col=0, parse_dates=True, header=10)
 
 Option 2: read column names and then data
 """""""""""""""""""""""""""""""""""""""""
@@ -1138,12 +1191,12 @@ Storing Attributes to a group node
 
 .. ipython:: python
 
-   df = pd.DataFrame(np.random.randn(8,3))
+   df = pd.DataFrame(np.random.randn(8, 3))
    store = pd.HDFStore('test.h5')
-   store.put('df',df)
+   store.put('df', df)
 
    # you can store an arbitrary Python object via pickle
-   store.get_storer('df').attrs.my_attribute = dict(A = 10)
+   store.get_storer('df').attrs.my_attribute = {'A': 10}
    store.get_storer('df').attrs.my_attribute
 
 .. ipython:: python
@@ -1267,6 +1320,7 @@ The `method` argument within `DataFrame.corr` can accept a callable in addition
     ...     return cov_ab / std_a / std_b
     ...
     ...
+    ...
     >>> df = pd.DataFrame(np.random.normal(size=(100, 3)))
     ...
     >>> df.corr(method=distcorr)
@@ -1285,17 +1339,17 @@ The :ref:`Timedeltas <timedeltas.timedeltas>` docs.
 
 .. ipython:: python
 
-   s  = pd.Series(pd.date_range('2012-1-1', periods=3, freq='D'))
+   s = pd.Series(pd.date_range('2012-1-1', periods=3, freq='D'))
 
    s - s.max()
 
    s.max() - s
 
-   s - datetime.datetime(2011,1,1,3,5)
+   s - datetime.datetime(2011, 1, 1, 3, 5)
 
    s + datetime.timedelta(minutes=5)
 
-   datetime.datetime(2011,1,1,3,5) - s
+   datetime.datetime(2011, 1, 1, 3, 5) - s
 
    datetime.timedelta(minutes=5) + s
 
@@ -1304,13 +1358,15 @@ The :ref:`Timedeltas <timedeltas.timedeltas>` docs.
 
 .. ipython:: python
 
-   deltas = pd.Series([ datetime.timedelta(days=i) for i in range(3) ])
+   deltas = pd.Series([datetime.timedelta(days=i) for i in range(3)])
 
-   df = pd.DataFrame(dict(A = s, B = deltas)); df
+   df = pd.DataFrame({'A': s, 'B': deltas})
+   df
 
-   df['New Dates'] = df['A'] + df['B'];
+   df['New Dates'] = df['A'] + df['B']
 
-   df['Delta'] = df['A'] - df['New Dates']; df
+   df['Delta'] = df['A'] - df['New Dates']
+   df
 
    df.dtypes
 
@@ -1321,9 +1377,11 @@ Values can be set to NaT using np.nan, similar to datetime
 
 .. ipython:: python
 
-   y = s - s.shift(); y
+   y = s - s.shift()
+   y
 
-   y[1] = np.nan; y
+   y[1] = np.nan
+   y
 
 Aliasing Axis Names
 -------------------
@@ -1333,23 +1391,24 @@ To globally provide aliases for axis names, one can define these 2 functions:
 .. ipython:: python
 
    def set_axis_alias(cls, axis, alias):
-      if axis not in cls._AXIS_NUMBERS:
-         raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
-      cls._AXIS_ALIASES[alias] = axis
+       if axis not in cls._AXIS_NUMBERS:
+           raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
+       cls._AXIS_ALIASES[alias] = axis
 
 .. ipython:: python
 
    def clear_axis_alias(cls, axis, alias):
-      if axis not in cls._AXIS_NUMBERS:
-         raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
-      cls._AXIS_ALIASES.pop(alias,None)
+       if axis not in cls._AXIS_NUMBERS:
+           raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
+       cls._AXIS_ALIASES.pop(alias, None)
 
 .. ipython:: python
 
-   set_axis_alias(pd.DataFrame,'columns', 'myaxis2')
-   df2 = pd.DataFrame(np.random.randn(3,2),columns=['c1','c2'],index=['i1','i2','i3'])
+   set_axis_alias(pd.DataFrame, 'columns', 'myaxis2')
+   df2 = pd.DataFrame(np.random.randn(3, 2), columns=['c1', 'c2'],
+                      index=['i1', 'i2', 'i3'])
    df2.sum(axis='myaxis2')
-   clear_axis_alias(pd.DataFrame,'columns', 'myaxis2')
+   clear_axis_alias(pd.DataFrame, 'columns', 'myaxis2')
 
 Creating Example Data
 ---------------------
@@ -1362,11 +1421,11 @@ of the data values:
 
 
    def expand_grid(data_dict):
-      rows = itertools.product(*data_dict.values())
-      return pd.DataFrame.from_records(rows, columns=data_dict.keys())
+       rows = itertools.product(*data_dict.values())
+       return pd.DataFrame.from_records(rows, columns=data_dict.keys())
 
    df = expand_grid(
-      {'height': [60, 70],
-       'weight': [100, 140, 180],
-       'sex': ['Male', 'Female']})
+       {'height': [60, 70],
+        'weight': [100, 140, 180],
+        'sex': ['Male', 'Female']})
    df


Code review comments:
diff_hunk: @@ -488,13 +531,13 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   S = pd.Series([i / 100.0 for i in range(1,11)])
+   S = pd.Series([i / 100.0 for i in range(1, 11)])
 
-   def CumRet(x,y):
-      return x * (1 + y)
+   def CumRet(x, y):
+       return x * (1 + y)
 
    def Red(x):
path: doc/source/cookbook.rst
text: @user1:
use `red`, I don't think there is a reason to have these functions named as classes

diff_hunk: @@ -562,11 +606,12 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-      {u'line_race': [10, 10, 8, 10, 10, 8],
-       u'beyer': [99, 102, 103, 103, 88, 100]},
-       index=[u'Last Gunfighter', u'Last Gunfighter', u'Last Gunfighter',
-              u'Paynter', u'Paynter', u'Paynter']); df
+   df = pd.DataFrame({u'line_race': [10, 10, 8, 10, 10, 8],
+                      u'beyer': [99, 102, 103, 103, 88, 100]},
+                     index=[u'Last Gunfighter', u'Last Gunfighter',
+                            u'Last Gunfighter', u'Paynter', u'Paynter',
+                            u'Paynter'])
path: doc/source/cookbook.rst
text: @user1:
You can remove all the `u''`, we'll be supporting Python 3 only very soon.

diff_hunk: @@ -694,15 +754,18 @@ Rolling Apply to multiple columns where function calculates a Series before a Sc
 
 .. ipython:: python
 
-   df = pd.DataFrame(data=np.random.randn(2000,2)/10000,
-                     index=pd.date_range('2001-01-01',periods=2000),
-                     columns=['A','B']); df
+   df = pd.DataFrame(data=np.random.randn(2000, 2) / 10000,
+                     index=pd.date_range('2001-01-01', periods=2000),
+                     columns=['A', 'B'])
+   df
 
-   def gm(aDF,Const):
-      v = ((((aDF.A+aDF.B)+1).cumprod())-1)*Const
-      return (aDF.index[0],v.iloc[-1])
+   def gm(aDF, Const):
path: doc/source/cookbook.rst
text: @user1:
Can you use `df` and `const` instead?

diff_hunk: @@ -871,8 +944,8 @@ The :ref:`Plotting <visualization>` docs.
 .. ipython:: python
 
    df = pd.DataFrame(
-        {u'stratifying_var': np.random.uniform(0, 100, 20),
-         u'price': np.random.normal(100, 5, 20)})
+       {u'stratifying_var': np.random.uniform(0, 100, 20),
+        u'price': np.random.normal(100, 5, 20)})
path: doc/source/cookbook.rst
text: @user1:
also can remove the `u''` here, and below

diff_hunk: @@ -105,11 +108,14 @@ Splitting
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
-   dflow = df[df.AAA <= 5]; dflow
-   dfhigh = df[df.AAA > 5]; dfhigh
+   dflow = df[df.AAA <= 5]
+   dflow
+   dfhigh = df[df.AAA > 5]
+   dfhigh
path: doc/source/cookbook.rst
text: @user1:
If those are not being used later, I'd show the result directly, instead of assigning them to a variable first.

diff_hunk: @@ -193,18 +204,22 @@ The :ref:`indexing <indexing>` docs.
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
-   df[(df.AAA <= 6) & (df.index.isin([0,2,4]))]
+   df[(df.AAA <= 6) & (df.index.isin([0, 2, 4]))]
 
 `Use loc for label-oriented slicing and iloc positional slicing
 <https://github.com/pandas-dev/pandas/issues/2904>`__
 
 .. ipython:: python
 
-   data = {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}
-   df = pd.DataFrame(data=data,index=['foo','bar','boo','kar']); df
+   data = {'AAA': [4, 5, 6, 7],
+           'BBB': [10, 20, 30, 40],
+           'CCC': [100, 50, -30, -50]}
+   df = pd.DataFrame(data=data, index=['foo', 'bar', 'boo', 'kar'])
path: doc/source/cookbook.rst
text: @user1:
For consistency I'd create `df` as the previous. The `BBB` looks good here, what will be different from the previous is that it'll have the index set.

diff_hunk: @@ -488,13 +531,13 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
 
 .. ipython:: python
 
-   S = pd.Series([i / 100.0 for i in range(1,11)])
+   S = pd.Series([i / 100.0 for i in range(1, 11)])
 
-   def CumRet(x,y):
-      return x * (1 + y)
+   def CumRet(x, y):
path: doc/source/cookbook.rst
text: @user1:
Can you use `cum_ret` instead

diff_hunk: @@ -119,45 +125,50 @@ Building Criteria
 
 .. ipython:: python
 
-   df = pd.DataFrame(
-        {'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df
+   df = pd.DataFrame({'AAA': [4, 5, 6, 7], 'BBB': [10, 20, 30, 40],
+                      'CCC': [100, 50, -30, -50]})
+   df
 
 ...and (without assignment returns a Series)
 
 .. ipython:: python
 
-   newseries = df.loc[(df['BBB'] < 25) & (df['CCC'] >= -40), 'AAA']; newseries
+   newseries = df.loc[(df['BBB'] < 25) & (df['CCC'] >= -40), 'AAA']
+   newseries
path: doc/source/cookbook.rst
text: @user1:
Same about not assigning