Repository: pandas-dev/pandas
Pull request: DOC: Fix format of basics.rst, following PEP-8 standard
- [x] closes #23792 
- [x] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

I updated the format of `doc/source/basics.rst` file. 
I do not see any errors when I run `flake8-rst doc/source/basics.rst`.

Please let me know if there are some changes.

Problem statement:
DOC: Fix format of basics.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/basics.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/basics.rst 
doc/source/basics.rst:309:10: E225 missing whitespace around operator
doc/source/basics.rst:6:4: E902 TokenError: EOF in multi-line statement
doc/source/basics.rst:152:28: E203 whitespace before ':'
doc/source/basics.rst:152:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:153:28: E203 whitespace before ':'
doc/source/basics.rst:153:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:154:30: E203 whitespace before ':'
doc/source/basics.rst:154:83: E501 line too long (83 > 79 characters)
doc/source/basics.rst:175:46: E231 missing whitespace after ','
doc/source/basics.rst:175:51: E231 missing whitespace after ','
doc/source/basics.rst:175:54: E231 missing whitespace after ','
doc/source/basics.rst:175:59: E231 missing whitespace after ','
doc/source/basics.rst:175:62: E231 missing whitespace after ','
doc/source/basics.rst:175:67: E231 missing whitespace after ','
doc/source/basics.rst:175:70: E231 missing whitespace after ','
doc/source/basics.rst:176:57: E231 missing whitespace after ','
doc/source/basics.rst:339:6: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:339:15: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:340:7: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:340:16: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:355:7: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:355:21: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:362:29: E231 missing whitespace after ':'
doc/source/basics.rst:363:29: E231 missing whitespace after ':'
doc/source/basics.rst:363:59: E231 missing whitespace after ','
doc/source/basics.rst:363:61: E231 missing whitespace after ','
doc/source/basics.rst:426:27: E203 whitespace before ':'
doc/source/basics.rst:427:27: E203 whitespace before ':'
doc/source/basics.rst:428:27: E203 whitespace before ':'
doc/source/basics.rst:429:27: E203 whitespace before ':'
doc/source/basics.rst:446:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:549:17: E221 multiple spaces before operator
doc/source/basics.rst:566:84: E501 line too long (81 > 79 characters)
doc/source/basics.rst:622:40: E231 missing whitespace after ','
doc/source/basics.rst:622:57: E231 missing whitespace after ','
doc/source/basics.rst:622:61: E231 missing whitespace after ','
doc/source/basics.rst:751:4: E402 module level import not at top of file
doc/source/basics.rst:756:19: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:756:21: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:760:4: E124 closing bracket does not match visual indentation
doc/source/basics.rst:883:83: E501 line too long (86 > 79 characters)
doc/source/basics.rst:927:7: E111 indentation is not a multiple of four
doc/source/basics.rst:980:4: E402 module level import not at top of file
doc/source/basics.rst:1041:39: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1048:41: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1059:49: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1067:50: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1087:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:1099:24: E203 whitespace before ':'
doc/source/basics.rst:1099:38: E203 whitespace before ':'
doc/source/basics.rst:1115:4: E402 module level import not at top of file
doc/source/basics.rst:1124:36: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1152:15: E126 continuation line over-indented for hanging indent
doc/source/basics.rst:1152:27: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1152:37: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1162:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:1162:23: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1162:34: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1164:32: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:1164:34: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:1164:43: E231 missing whitespace after ','
doc/source/basics.rst:1166:16: E231 missing whitespace after ','
doc/source/basics.rst:1166:18: E231 missing whitespace after ','
doc/source/basics.rst:1172:28: E201 whitespace after '['
doc/source/basics.rst:1172:47: E231 missing whitespace after ','
doc/source/basics.rst:1172:49: E231 missing whitespace after ','
doc/source/basics.rst:1173:28: E128 continuation line under-indented for visual indent
doc/source/basics.rst:1173:54: E202 whitespace before ']'
doc/source/basics.rst:1175:16: E231 missing whitespace after ','
doc/source/basics.rst:1175:18: E231 missing whitespace after ','
doc/source/basics.rst:1505:38: E203 whitespace before ':'
doc/source/basics.rst:1505:67: E203 whitespace before ':'
doc/source/basics.rst:1628:34: E231 missing whitespace after ','
doc/source/basics.rst:1679:14: E225 missing whitespace around operator
doc/source/basics.rst:1775:28: E203 whitespace before ':'
doc/source/basics.rst:1775:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:1776:28: E203 whitespace before ':'
doc/source/basics.rst:1776:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:1777:30: E203 whitespace before ':'
doc/source/basics.rst:1777:83: E501 line too long (83 > 79 characters)
doc/source/basics.rst:1803:29: E231 missing whitespace after ':'
doc/source/basics.rst:1803:32: E231 missing whitespace after ','
doc/source/basics.rst:1803:34: E231 missing whitespace after ','
doc/source/basics.rst:1803:36: E231 missing whitespace after ','
doc/source/basics.rst:1803:39: E231 missing whitespace after ','
doc/source/basics.rst:1803:45: E231 missing whitespace after ':'
doc/source/basics.rst:1803:48: E231 missing whitespace after ','
doc/source/basics.rst:1803:50: E231 missing whitespace after ','
doc/source/basics.rst:1803:52: E231 missing whitespace after ','
doc/source/basics.rst:1803:55: E231 missing whitespace after ','
doc/source/basics.rst:1803:63: E231 missing whitespace after ':'
doc/source/basics.rst:1803:66: E231 missing whitespace after ','
doc/source/basics.rst:1803:68: E231 missing whitespace after ','
doc/source/basics.rst:1803:70: E231 missing whitespace after ','
doc/source/basics.rst:1810:54: E231 missing whitespace after ','
doc/source/basics.rst:1913:49: E231 missing whitespace after ','
doc/source/basics.rst:1913:56: E231 missing whitespace after ','
doc/source/basics.rst:1913:61: E231 missing whitespace after ','
doc/source/basics.rst:1913:68: E231 missing whitespace after ','
doc/source/basics.rst:1913:73: E231 missing whitespace after ','
doc/source/basics.rst:1913:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:1914:27: E231 missing whitespace after ','
doc/source/basics.rst:1986:5: E999 SyntaxError: invalid syntax
doc/source/basics.rst:2010:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:2124:85: E501 line too long (83 > 79 characters)
doc/source/basics.rst:2212:84: E501 line too long (81 > 79 characters)
```

After fixing this issue, the previous command should not report any error.

Hints from issue discussion:
Hi @datapythonista ,
I would like to work on this issue, if you do not mind!
Sure, thank for helping @ywpark1!

Commit message: DOC: Fix format of basics.rst, following PEP-8 standard(panda-dev#23792)

Patch to review:
diff --git a/doc/source/basics.rst b/doc/source/basics.rst
index d19fcedf4e766..ba840ef92fe7e 100644
--- a/doc/source/basics.rst
+++ b/doc/source/basics.rst
@@ -149,9 +149,10 @@ either match on the *index* or *columns* via the **axis** keyword:
 
 .. ipython:: python
 
-   df = pd.DataFrame({'one' : pd.Series(np.random.randn(3), index=['a', 'b', 'c']),
-                      'two' : pd.Series(np.random.randn(4), index=['a', 'b', 'c', 'd']),
-                      'three' : pd.Series(np.random.randn(3), index=['b', 'c', 'd'])})
+   df = pd.DataFrame({
+       'one': pd.Series(np.random.randn(3), index=['a', 'b', 'c']),
+       'two': pd.Series(np.random.randn(4), index=['a', 'b', 'c', 'd']),
+       'three': pd.Series(np.random.randn(3), index=['b', 'c', 'd'])})
    df
    row = df.iloc[1]
    column = df['two']
@@ -172,8 +173,8 @@ Furthermore you can align a level of a MultiIndexed DataFrame with a Series.
 .. ipython:: python
 
    dfmi = df.copy()
-   dfmi.index = pd.MultiIndex.from_tuples([(1,'a'),(1,'b'),(1,'c'),(2,'a')],
-                                          names=['first','second'])
+   dfmi.index = pd.MultiIndex.from_tuples([
+       (1, 'a'), (1, 'b'), (1, 'c'), (2, 'a')], names=['first', 'second'])
    dfmi.sub(column, axis=0, level='second')
 
 With Panel, describing the matching behavior is a bit more difficult, so
@@ -306,14 +307,14 @@ To evaluate single-element pandas objects in a boolean context, use the method
 
    .. code-block:: python
 
-       >>> if df:                         # noqa: E999
-               ...
+      >>> if df:
+      ...     pass
 
    Or
 
    .. code-block:: python
 
-       >>> df and df2
+      >>> df and df2
 
    These will both raise errors, as you are trying to compare multiple values.
 
@@ -329,17 +330,17 @@ Comparing if objects are equivalent
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Often you may find that there is more than one way to compute the same
-result.  As a simple example, consider ``df+df`` and ``df*2``. To test
+result.  As a simple example, consider ``df + df`` and ``df * 2``. To test
 that these two computations produce the same result, given the tools
-shown above, you might imagine using ``(df+df == df*2).all()``. But in
+shown above, you might imagine using ``(df + df == df * 2).all()``. But in
 fact, this expression is False:
 
 .. ipython:: python
 
-   df+df == df*2
-   (df+df == df*2).all()
+   df + df == df * 2
+   (df + df == df * 2).all()
 
-Notice that the boolean DataFrame ``df+df == df*2`` contains some False values!
+Notice that the boolean DataFrame ``df + df == df * 2`` contains some False values!
 This is because NaNs do not compare as equals:
 
 .. ipython:: python
@@ -352,15 +353,15 @@ corresponding locations treated as equal.
 
 .. ipython:: python
 
-   (df+df).equals(df*2)
+   (df + df).equals(df * 2)
 
 Note that the Series or DataFrame index needs to be in the same order for
 equality to be True:
 
 .. ipython:: python
 
-   df1 = pd.DataFrame({'col':['foo', 0, np.nan]})
-   df2 = pd.DataFrame({'col':[np.nan, 0, 'foo']}, index=[2,1,0])
+   df1 = pd.DataFrame({'col': ['foo', 0, np.nan]})
+   df2 = pd.DataFrame({'col': [np.nan, 0, 'foo']}, index=[2, 1, 0])
    df1.equals(df2)
    df1.equals(df2.sort_index())
 
@@ -423,10 +424,10 @@ which we illustrate:
 
 .. ipython:: python
 
-   df1 = pd.DataFrame({'A' : [1., np.nan, 3., 5., np.nan],
-                       'B' : [np.nan, 2., 3., np.nan, 6.]})
-   df2 = pd.DataFrame({'A' : [5., 2., 4., np.nan, 3., 7.],
-                       'B' : [np.nan, np.nan, 3., 4., 6., 8.]})
+   df1 = pd.DataFrame({'A': [1., np.nan, 3., 5., np.nan],
+                       'B': [np.nan, 2., 3., np.nan, 6.]})
+   df2 = pd.DataFrame({'A': [5., 2., 4., np.nan, 3., 7.],
+                       'B': [np.nan, np.nan, 3., 4., 6., 8.]})
    df1
    df2
    df1.combine_first(df2)
@@ -443,7 +444,8 @@ So, for instance, to reproduce :meth:`~DataFrame.combine_first` as above:
 
 .. ipython:: python
 
-   combiner = lambda x, y: np.where(pd.isna(x), y, x)
+   def combiner(x, y):
+       np.where(pd.isna(x), y, x)
    df1.combine(df2, combiner)
 
 .. _basics.stats:
@@ -546,7 +548,7 @@ Series:
 
    series = pd.Series(np.random.randn(500))
    series[20:500] = np.nan
-   series[10:20]  = 5
+   series[10:20] = 5
    series.nunique()
 
 .. _basics.describe:
@@ -563,7 +565,8 @@ course):
     series = pd.Series(np.random.randn(1000))
     series[::2] = np.nan
     series.describe()
-    frame = pd.DataFrame(np.random.randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
+    frame = pd.DataFrame(
+        np.random.randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
     frame.iloc[::2] = np.nan
     frame.describe()
 
@@ -619,7 +622,7 @@ corresponding values:
    s1
    s1.idxmin(), s1.idxmax()
 
-   df1 = pd.DataFrame(np.random.randn(5,3), columns=['A','B','C'])
+   df1 = pd.DataFrame(np.random.randn(5, 3), columns=['A', 'B', 'C'])
    df1
    df1.idxmin(axis=0)
    df1.idxmax(axis=1)
@@ -753,11 +756,11 @@ For example, we can fit a regression using statsmodels. Their API expects a form
    bb = pd.read_csv('data/baseball.csv', index_col='id')
 
    (bb.query('h > 0')
-      .assign(ln_h = lambda df: np.log(df.h))
+      .assign(ln_h=lambda df: np.log(df.h))
       .pipe((sm.ols, 'data'), 'hr ~ ln_h + year + g + C(lg)')
       .fit()
       .summary()
-   )
+    )
 
 The pipe method is inspired by unix pipes and more recently dplyr_ and magrittr_, which
 have introduced the popular ``(%>%)`` (read pipe) operator for R_.
@@ -880,7 +883,8 @@ output:
 
    tsdf.agg('sum')
 
-   # these are equivalent to a ``.sum()`` because we are aggregating on a single function
+   # these are equivalent to a ``.sum()`` because we are aggregating
+   # on a single function
    tsdf.sum()
 
 Single aggregations on a ``Series`` this will return a scalar value:
@@ -924,7 +928,7 @@ Passing a named function will yield that name for the row:
 .. ipython:: python
 
    def mymean(x):
-      return x.mean()
+       return x.mean()
 
    tsdf.A.agg(['sum', mymean])
 
@@ -1038,14 +1042,14 @@ will be the names of the transforming functions.
 
 .. ipython:: python
 
-   tsdf.transform([np.abs, lambda x: x+1])
+   tsdf.transform([np.abs, lambda x: x + 1])
 
 Passing multiple functions to a Series will yield a DataFrame. The
 resulting column names will be the transforming functions.
 
 .. ipython:: python
 
-   tsdf.A.transform([np.abs, lambda x: x+1])
+   tsdf.A.transform([np.abs, lambda x: x + 1])
 
 
 Transforming with a dict
@@ -1056,7 +1060,7 @@ Passing a dict of functions will allow selective transforming per column.
 
 .. ipython:: python
 
-   tsdf.transform({'A': np.abs, 'B': lambda x: x+1})
+   tsdf.transform({'A': np.abs, 'B': lambda x: x + 1})
 
 Passing a dict of lists will generate a MultiIndexed DataFrame with these
 selective transforms.
@@ -1064,7 +1068,7 @@ selective transforms.
 .. ipython:: python
    :okwarning:
 
-   tsdf.transform({'A': np.abs, 'B': [lambda x: x+1, 'sqrt']})
+   tsdf.transform({'A': np.abs, 'B': [lambda x: x + 1, 'sqrt']})
 
 .. _basics.elementwise:
 
@@ -1084,7 +1088,8 @@ a single value and returning a single value. For example:
 .. ipython:: python
 
    df4
-   f = lambda x: len(str(x))
+   def f(x):
+       len(str(x))
    df4['one'].map(f)
    df4.applymap(f)
 
@@ -1096,7 +1101,7 @@ to :ref:`merging/joining functionality <merging>`:
 
    s = pd.Series(['six', 'seven', 'six', 'seven', 'six'],
                  index=['a', 'b', 'c', 'd', 'e'])
-   t = pd.Series({'six' : 6., 'seven' : 7.})
+   t = pd.Series({'six': 6., 'seven': 7.})
    s
    s.map(t)
 
@@ -1121,7 +1126,7 @@ A transformational apply.
 
 .. ipython:: python
 
-   result = panel.apply(lambda x: x*2, axis='items')
+   result = panel.apply(lambda x: x * 2, axis='items')
    result
    result['ItemA']
 
@@ -1149,8 +1154,8 @@ the z-score across the ``major_axis``.
 .. ipython:: python
 
    result = panel.apply(
-              lambda x: (x-x.mean())/x.std(),
-              axis='major_axis')
+       lambda x: (x - x.mean()) / x.std(),
+       axis='major_axis')
    result
    result['ItemA']
 
@@ -1159,20 +1164,21 @@ Apply can also accept multiple axes in the ``axis`` argument. This will pass a
 
 .. ipython:: python
 
-   f = lambda x: ((x.T-x.mean(1))/x.std(1)).T
+   def f(x):
+       ((x.T - x.mean(1)) / x.std(1)).T
 
-   result = panel.apply(f, axis = ['items','major_axis'])
+   result = panel.apply(f, axis=['items', 'major_axis'])
    result
-   result.loc[:,:,'ItemA']
+   result.loc[:, :, 'ItemA']
 
 This is equivalent to the following:
 
 .. ipython:: python
 
-   result = pd.Panel(dict([ (ax, f(panel.loc[:,:,ax]))
-                           for ax in panel.minor_axis ]))
+   result = pd.Panel(dict([
+       (ax, f(panel.loc[:, :, ax])) for ax in panel.minor_axis]))
    result
-   result.loc[:,:,'ItemA']
+   result.loc[:, :, 'ItemA']
 
 
 .. _basics.reindexing:
@@ -1500,14 +1506,16 @@ In short, basic iteration (``for i in object``) produces:
 
 Thus, for example, iterating over a DataFrame gives you the column names:
 
-.. ipython::
+.. ipython:: python
+
+   df = pd.DataFrame({
+       'col1': np.random.randn(3),
+       'col2': np.random.randn(3)},
+       index=['a', 'b', 'c'])
 
-    In [0]: df = pd.DataFrame({'col1' : np.random.randn(3), 'col2' : np.random.randn(3)},
-       ...:                   index=['a', 'b', 'c'])
+   for col in df:
+       print(col)
 
-    In [0]: for col in df:
-       ...:     print(col)
-       ...:
 
 Pandas objects also have the dict-like :meth:`~DataFrame.iteritems` method to
 iterate over the (key, value) pairs.
@@ -1570,12 +1578,11 @@ through key-value pairs:
 
 For example:
 
-.. ipython::
+.. ipython:: python
 
-   In [0]: for item, frame in wp.iteritems():
-      ...:     print(item)
-      ...:     print(frame)
-      ...:
+   for item, frame in wp.iteritems():
+       print(item)
+       print(frame)
 
 .. _basics.iterrows:
 
@@ -1586,11 +1593,10 @@ iterrows
 DataFrame as Series objects. It returns an iterator yielding each
 index value along with a Series containing the data in each row:
 
-.. ipython::
+.. ipython:: python
 
-   In [0]: for row_index, row in df.iterrows():
-      ...:     print('%s\n%s' % (row_index, row))
-      ...:
+   for row_index, row in df.iterrows():
+       print(row_index, row, sep='\n')
 
 .. note::
 
@@ -1625,7 +1631,7 @@ For instance, a contrived way to transpose the DataFrame would be:
    print(df2)
    print(df2.T)
 
-   df2_t = pd.DataFrame(dict((idx,values) for idx, values in df2.iterrows()))
+   df2_t = pd.DataFrame(dict((idx, values) for idx, values in df2.iterrows()))
    print(df2_t)
 
 itertuples
@@ -1676,7 +1682,7 @@ This enables nice expressions like this:
 
 .. ipython:: python
 
-   s[s.dt.day==2]
+   s[s.dt.day == 2]
 
 You can easily produces tz aware transformations:
 
@@ -1772,9 +1778,10 @@ used to sort a pandas object by its index levels.
 
 .. ipython:: python
 
-   df = pd.DataFrame({'one' : pd.Series(np.random.randn(3), index=['a', 'b', 'c']),
-                      'two' : pd.Series(np.random.randn(4), index=['a', 'b', 'c', 'd']),
-                      'three' : pd.Series(np.random.randn(3), index=['b', 'c', 'd'])})
+   df = pd.DataFrame({
+       'one': pd.Series(np.random.randn(3), index=['a', 'b', 'c']),
+       'two': pd.Series(np.random.randn(4), index=['a', 'b', 'c', 'd']),
+       'three': pd.Series(np.random.randn(3), index=['b', 'c', 'd'])})
 
    unsorted_df = df.reindex(index=['a', 'd', 'c', 'b'],
                             columns=['three', 'two', 'one'])
@@ -1800,14 +1807,15 @@ to use to determine the sorted order.
 
 .. ipython:: python
 
-   df1 = pd.DataFrame({'one':[2,1,1,1],'two':[1,3,2,4],'three':[5,4,3,2]})
+   df1 = pd.DataFrame({
+       'one': [2, 1, 1, 1], 'two': [1, 3, 2, 4], 'three': [5, 4, 3, 2]})
    df1.sort_values(by='two')
 
 The ``by`` parameter can take a list of column names, e.g.:
 
 .. ipython:: python
 
-   df1[['one', 'two', 'three']].sort_values(by=['one','two'])
+   df1[['one', 'two', 'three']].sort_values(by=['one', 'two'])
 
 These methods have special treatment of NA values via the ``na_position``
 argument:
@@ -1910,8 +1918,9 @@ all levels to ``by``.
 
 .. ipython:: python
 
-   df1.columns = pd.MultiIndex.from_tuples([('a','one'),('a','two'),('b','three')])
-   df1.sort_values(by=('a','two'))
+   df1.columns = pd.MultiIndex.from_tuples([
+       ('a', 'one'), ('a', 'two'), ('b', 'three')])
+   df1.sort_values(by=('a', 'two'))
 
 
 Copying
@@ -1960,13 +1969,13 @@ with the data type of each column.
 
 .. ipython:: python
 
-   dft = pd.DataFrame(dict(A = np.random.rand(3),
-                           B = 1,
-                           C = 'foo',
-                           D = pd.Timestamp('20010102'),
-                           E = pd.Series([1.0]*3).astype('float32'),
-			               F = False,
-			               G = pd.Series([1]*3,dtype='int8')))
+   dft = pd.DataFrame(dict(A=np.random.rand(3),
+                           B=1,
+                           C='foo',
+                           D=pd.Timestamp('20010102'),
+                           E=pd.Series([1.0] * 3).astype('float32'),
+                           F=False,
+                           G=pd.Series([1] * 3, dtype='int8')))
    dft
    dft.dtypes
 
@@ -2005,9 +2014,10 @@ different numeric dtypes will **NOT** be combined. The following example will gi
    df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32')
    df1
    df1.dtypes
-   df2 = pd.DataFrame(dict( A = pd.Series(np.random.randn(8), dtype='float16'),
-                           B = pd.Series(np.random.randn(8)),
-                           C = pd.Series(np.array(np.random.randn(8), dtype='uint8')) ))
+   df2 = pd.DataFrame(dict(A=pd.Series(np.random.randn(8), dtype='float16'),
+                           B=pd.Series(np.random.randn(8)),
+                           C=pd.Series(np.array(np.random.randn(8),
+                                                dtype='uint8'))))
    df2
    df2.dtypes
 
@@ -2022,7 +2032,7 @@ The following will all result in ``int64`` dtypes.
 
    pd.DataFrame([1, 2], columns=['a']).dtypes
    pd.DataFrame({'a': [1, 2]}).dtypes
-   pd.DataFrame({'a': 1 }, index=list(range(2))).dtypes
+   pd.DataFrame({'a': 1}, index=list(range(2))).dtypes
 
 Note that Numpy will choose *platform-dependent* types when creating arrays.
 The following **WILL** result in ``int32`` on 32-bit platform.
@@ -2077,8 +2087,8 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`.
 
 .. ipython:: python
 
-   dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
-   dft[['a','b']] = dft[['a','b']].astype(np.uint8)
+   dft = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
+   dft[['a', 'b']] = dft[['a', 'b']].astype(np.uint8)
    dft
    dft.dtypes
 
@@ -2088,7 +2098,7 @@ Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFra
 
 .. ipython:: python
 
-   dft1 = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
+   dft1 = pd.DataFrame({'a': [1, 0, 1], 'b': [4, 5, 6], 'c': [7, 8, 9]})
    dft1 = dft1.astype({'a': np.bool, 'c': np.float64})
    dft1
    dft1.dtypes
@@ -2101,7 +2111,7 @@ Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFra
 
     .. ipython:: python
 
-       dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
+       dft = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
        dft.loc[:, ['a', 'b']].astype(np.uint8).dtypes
        dft.loc[:, ['a', 'b']] = dft.loc[:, ['a', 'b']].astype(np.uint8)
        dft.dtypes
@@ -2121,7 +2131,8 @@ to the correct type.
      import datetime
      df = pd.DataFrame([[1, 2],
                         ['a', 'b'],
-                        [datetime.datetime(2016, 3, 2), datetime.datetime(2016, 3, 2)]])
+                        [datetime.datetime(2016, 3, 2),
+                        datetime.datetime(2016, 3, 2)]])
      df = df.T
      df
      df.dtypes
@@ -2209,7 +2220,8 @@ as DataFrames. However, with :meth:`~pandas.DataFrame.apply`, we can "apply" the
 .. ipython:: python
 
     import datetime
-    df = pd.DataFrame([['2016-07-09', datetime.datetime(2016, 3, 2)]] * 2, dtype='O')
+    df = pd.DataFrame([
+        ['2016-07-09', datetime.datetime(2016, 3, 2)]] * 2, dtype='O')
     df
     df.apply(pd.to_datetime)
 
@@ -2235,7 +2247,7 @@ See also :ref:`Support for integer NA <gotchas.intna>`.
    dfi
    dfi.dtypes
 
-   casted = dfi[dfi>0]
+   casted = dfi[dfi > 0]
    casted
    casted.dtypes
 
@@ -2247,7 +2259,7 @@ While float dtypes are unchanged.
    dfa['A'] = dfa['A'].astype('float32')
    dfa.dtypes
 
-   casted = dfa[df2>0]
+   casted = dfa[df2 > 0]
    casted
    casted.dtypes
 
@@ -2336,4 +2348,4 @@ All NumPy dtypes are subclasses of ``numpy.generic``:
 .. note::
 
     Pandas also defines the types ``category``, and ``datetime64[ns, tz]``, which are not integrated into the normal
-    NumPy hierarchy and won't show up with the above function.
+    NumPy hierarchy and won't show up with the above function.
\ No newline at end of file


Code review comments:
diff_hunk: @@ -1159,20 +1164,21 @@ Apply can also accept multiple axes in the ``axis`` argument. This will pass a
 
 .. ipython:: python
 
-   f = lambda x: ((x.T-x.mean(1))/x.std(1)).T
+   def f(x):
+       ((x.T - x.mean(1)) / x.std(1)).T
 
-   result = panel.apply(f, axis = ['items','major_axis'])
+   result = panel.apply(f, axis=['items', 'major_axis'])
    result
-   result.loc[:,:,'ItemA']
+   result.loc[:, :, 'ItemA']
 
 This is equivalent to the following:
 
 .. ipython:: python
 
-   result = pd.Panel(dict([ (ax, f(panel.loc[:,:,ax]))
-                           for ax in panel.minor_axis ]))
+   result = pd.Panel(dict([
+       (ax, f(panel.loc[:, :, ax])) for ax in panel.minor_axis]))
    result
-   result.loc[:,:,'ItemA']
+   result.loc[:, :, 'ItemA']
path: doc/source/basics.rst
text: @user1:
I don't directly see how the above changes cause this, but, this example is now failing in the doc build with:

```
>>>-------------------------------------------------------------------------
Exception in /home/travis/build/pandas-dev/pandas/doc/source/basics.rst at block ending on line 1183
Specify :okexcept: as an option in the ipython:: block to suppress this message

KeyErrorTraceback (most recent call last)

~/build/pandas-dev/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3146             try:
-> 3147                 return self._engine.get_loc(key)
   3148             except KeyError:
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ItemA'

During handling of the above exception, another exception occurred:

KeyErrorTraceback (most recent call last)
<ipython-input-209-ce1c0f9e4a44> in <module>
----> 1 result.loc[:, :, 'ItemA']
~/build/pandas-dev/pandas/pandas/core/indexing.py in __getitem__(self, key)
   1495             except (KeyError, IndexError, AttributeError):
   1496                 pass
-> 1497             return self._getitem_tuple(key)
   1498         else:
   1499             # we by definition only have the 0th axis
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_tuple(self, tup)
    868     def _getitem_tuple(self, tup):
    869         try:
--> 870             return self._getitem_lowerdim(tup)
    871         except IndexingError:
    872             pass
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_lowerdim(self, tup)
    988         for i, key in enumerate(tup):
    989             if is_label_like(key) or isinstance(key, tuple):
--> 990                 section = self._getitem_axis(key, axis=i)
    991 
    992                 # we have yielded a scalar ?
~/build/pandas-dev/pandas/pandas/core/indexing.py in _getitem_axis(self, key, axis)
   1914         # fall thru to straight lookup
   1915         self._validate_key(key, axis)
-> 1916         return self._get_label(key, axis=axis)
   1917 
   1918 
~/build/pandas-dev/pandas/pandas/core/indexing.py in _get_label(self, label, axis)
    146             raise IndexingError('no slices here, handle elsewhere')
    147 
--> 148         return self.obj._xs(label, axis=axis)
    149 
    150     def _get_loc(self, key, axis=None):
~/build/pandas-dev/pandas/pandas/core/panel.py in xs(self, key, axis)
    864         self._consolidate_inplace()
    865         axis_number = self._get_axis_number(axis)
--> 866         new_data = self._data.xs(key, axis=axis_number, copy=False)
    867         result = self._construct_return_type(new_data)
    868         copy = new_data.is_mixed_type
~/build/pandas-dev/pandas/pandas/core/internals/managers.py in xs(self, key, axis, copy, takeable)
    835             loc = key
    836         else:
--> 837             loc = self.axes[axis].get_loc(key)
    838 
    839         slicer = [slice(None, None) for _ in range(self.ndim)]
~/build/pandas-dev/pandas/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3147                 return self._engine.get_loc(key)
   3148             except KeyError:
-> 3149                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   3150         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   3151         if indexer.ndim > 1 or indexer.size > 1:
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
~/build/pandas-dev/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'ItemA'
```