Skip to content

Commit 9fd9796

Browse files
committed
Add missing spaces, adjust the indentation, remove 'In [0]'
1 parent da683e6 commit 9fd9796

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

doc/source/basics.rst

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,13 @@ To evaluate single-element pandas objects in a boolean context, use the method
307307

308308
.. code-block:: python
309309
310-
>>> if df: # noqa: E999
311-
...
310+
>>> if df: # noqa: E999
312311
313312
Or
314313

315314
.. code-block:: python
316315
317-
>>> df and df2
316+
>>> df and df2
318317
319318
These will both raise errors, as you are trying to compare multiple values.
320319

@@ -330,17 +329,17 @@ Comparing if objects are equivalent
330329
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331330

332331
Often you may find that there is more than one way to compute the same
333-
result. As a simple example, consider ``df+df`` and ``df*2``. To test
332+
result. As a simple example, consider ``df + df`` and ``df * 2``. To test
334333
that these two computations produce the same result, given the tools
335-
shown above, you might imagine using ``(df+df == df*2).all()``. But in
334+
shown above, you might imagine using ``(df + df == df * 2).all()``. But in
336335
fact, this expression is False:
337336

338337
.. ipython:: python
339338
340339
df + df == df * 2
341340
(df + df == df * 2).all()
342341
343-
Notice that the boolean DataFrame ``df+df == df*2`` contains some False values!
342+
Notice that the boolean DataFrame ``df + df == df * 2`` contains some False values!
344343
This is because NaNs do not compare as equals:
345344

346345
.. ipython:: python
@@ -1506,14 +1505,15 @@ In short, basic iteration (``for i in object``) produces:
15061505

15071506
Thus, for example, iterating over a DataFrame gives you the column names:
15081507

1509-
.. ipython::
1508+
.. ipython:: python
1509+
1510+
df = pd.DataFrame(
1511+
{'col1': np.random.randn(3), 'col2': np.random.randn(3)},
1512+
index=['a', 'b', 'c'])
15101513
1511-
In [0]: df = pd.DataFrame({'col1': np.random.randn(3), 'col2': np.random.randn(3)},
1512-
...: index=['a', 'b', 'c'])
1514+
for col in df:
1515+
print(col)
15131516
1514-
In [0]: for col in df:
1515-
...: print(col)
1516-
...:
15171517
15181518
Pandas objects also have the dict-like :meth:`~DataFrame.iteritems` method to
15191519
iterate over the (key, value) pairs.
@@ -1576,12 +1576,11 @@ through key-value pairs:
15761576

15771577
For example:
15781578

1579-
.. ipython::
1579+
.. ipython:: python
15801580
1581-
In [0]: for item, frame in wp.iteritems():
1582-
...: print(item)
1583-
...: print(frame)
1584-
...:
1581+
for item, frame in wp.iteritems():
1582+
print(item)
1583+
print(frame)
15851584
15861585
.. _basics.iterrows:
15871586

@@ -1592,11 +1591,10 @@ iterrows
15921591
DataFrame as Series objects. It returns an iterator yielding each
15931592
index value along with a Series containing the data in each row:
15941593

1595-
.. ipython::
1594+
.. ipython:: python
15961595
1597-
In [0]: for row_index, row in df.iterrows():
1598-
...: print('%s\n%s' % (row_index, row))
1599-
...:
1596+
for row_index, row in df.iterrows():
1597+
print('%s\n%s' % (row_index, row))
16001598
16011599
.. note::
16021600

@@ -1969,10 +1967,12 @@ with the data type of each column.
19691967

19701968
.. ipython:: python
19711969
1972-
dft = pd.DataFrame(dict(A = np.random.rand(3), B = 1, C = 'foo',
1973-
D = pd.Timestamp('20010102'),
1974-
E = pd.Series([1.0]*3).astype('float32'),
1975-
F = False, G = pd.Series([1]*3,dtype='int8')))
1970+
dft = pd.DataFrame(dict(A=np.random.rand(3),
1971+
B=1,
1972+
C='foo',
1973+
D=pd.Timestamp('20010102'),
1974+
E=pd.Series([1.0] * 3).astype('float32'),
1975+
F=False, G=pd.Series([1] * 3, dtype='int8')))
19761976
dft
19771977
dft.dtypes
19781978
@@ -2011,10 +2011,10 @@ different numeric dtypes will **NOT** be combined. The following example will gi
20112011
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32')
20122012
df1
20132013
df1.dtypes
2014-
df2 = pd.DataFrame(dict(A = pd.Series(np.random.randn(8), dtype='float16'),
2015-
B = pd.Series(np.random.randn(8)),
2016-
C = pd.Series(np.array(
2017-
np.random.randn(8), dtype='uint8')) ))
2014+
df2 = pd.DataFrame(dict(A=pd.Series(np.random.randn(8), dtype='float16'),
2015+
B=pd.Series(np.random.randn(8)),
2016+
C=pd.Series(np.array(
2017+
np.random.randn(8), dtype='uint8'))))
20182018
df2
20192019
df2.dtypes
20202020
@@ -2029,7 +2029,7 @@ The following will all result in ``int64`` dtypes.
20292029
20302030
pd.DataFrame([1, 2], columns=['a']).dtypes
20312031
pd.DataFrame({'a': [1, 2]}).dtypes
2032-
pd.DataFrame({'a': 1 }, index=list(range(2))).dtypes
2032+
pd.DataFrame({'a': 1}, index=list(range(2))).dtypes
20332033
20342034
Note that Numpy will choose *platform-dependent* types when creating arrays.
20352035
The following **WILL** result in ``int32`` on 32-bit platform.
@@ -2084,8 +2084,8 @@ Convert a subset of columns to a specified type using :meth:`~DataFrame.astype`.
20842084

20852085
.. ipython:: python
20862086
2087-
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
2088-
dft[['a','b']] = dft[['a','b']].astype(np.uint8)
2087+
dft = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
2088+
dft[['a', 'b']] = dft[['a', 'b']].astype(np.uint8)
20892089
dft
20902090
dft.dtypes
20912091
@@ -2095,7 +2095,7 @@ Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFra
20952095

20962096
.. ipython:: python
20972097
2098-
dft1 = pd.DataFrame({'a': [1,0,1], 'b': [4,5,6], 'c': [7, 8, 9]})
2098+
dft1 = pd.DataFrame({'a': [1, 0, 1], 'b': [4, 5, 6], 'c': [7, 8, 9]})
20992099
dft1 = dft1.astype({'a': np.bool, 'c': np.float64})
21002100
dft1
21012101
dft1.dtypes
@@ -2108,7 +2108,7 @@ Convert certain columns to a specific dtype by passing a dict to :meth:`~DataFra
21082108

21092109
.. ipython:: python
21102110
2111-
dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
2111+
dft = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})
21122112
dft.loc[:, ['a', 'b']].astype(np.uint8).dtypes
21132113
dft.loc[:, ['a', 'b']] = dft.loc[:, ['a', 'b']].astype(np.uint8)
21142114
dft.dtypes
@@ -2244,7 +2244,7 @@ See also :ref:`Support for integer NA <gotchas.intna>`.
22442244
dfi
22452245
dfi.dtypes
22462246
2247-
casted = dfi[dfi>0]
2247+
casted = dfi[dfi > 0]
22482248
casted
22492249
casted.dtypes
22502250
@@ -2256,7 +2256,7 @@ While float dtypes are unchanged.
22562256
dfa['A'] = dfa['A'].astype('float32')
22572257
dfa.dtypes
22582258
2259-
casted = dfa[df2>0]
2259+
casted = dfa[df2 > 0]
22602260
casted
22612261
casted.dtypes
22622262

0 commit comments

Comments
 (0)