Skip to content

Commit 67cf043

Browse files
committed
revert back to minimal changes in doc folder
Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
1 parent 77df97f commit 67cf043

File tree

10 files changed

+148
-74
lines changed

10 files changed

+148
-74
lines changed

doc/source/advanced.rst

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,47 @@ method, allowing you to permute the hierarchical index levels in one step:
503503
504504
df[:5].reorder_levels([1,0], axis=0)
505505
506+
.. _advanced.index_names:
507+
508+
Renaming names of an ``Index`` or ``MultiIndex``
509+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
510+
511+
The :meth:`~DataFrame.rename` method is used to rename the labels of a
512+
``MultiIndex``, and is typically used to rename the columns of a ``DataFrame``.
513+
The ``columns`` argument of ``rename`` allows a dictionary to be specified
514+
that includes only the columns you wish to rename.
515+
516+
.. ipython:: python
517+
518+
df.rename(columns={0: "col0", 1: "col1"})
519+
520+
This method can also be used to rename specific labels of the main index
521+
of the ``DataFrame``.
522+
523+
.. ipython:: python
524+
525+
df.rename(index={"one" : "two", "y" : "z"})
526+
527+
The :meth:`~DataFrame.rename_axis` method is used to rename the name of a
528+
``Index`` or ``MultiIndex``. In particular, the names of the levels of a
529+
``MultiIndex`` can be specified, which is useful if ``reset_index()`` is later
530+
used to move the values from the ``MultiIndex`` to a column.
531+
532+
.. ipython:: python
533+
534+
df.rename_axis(index=['abc', 'def'])
535+
536+
Note that the columns of a ``DataFrame`` are an index, so that using
537+
``rename_axis`` with the ``columns`` argument will change the name of that
538+
index.
539+
540+
.. ipython:: python
541+
542+
df.rename_axis(columns="Cols").columns
543+
544+
Both ``rename`` and ``rename_axis`` support specifying a dictionary,
545+
``Series`` or a mapping function to map labels/names to new values.
546+
506547
Sorting a ``MultiIndex``
507548
------------------------
508549

@@ -738,15 +779,17 @@ values **not** in the categories, similarly to how you can reindex **any** panda
738779
Reshaping and Comparison operations on a ``CategoricalIndex`` must have the same categories
739780
or a ``TypeError`` will be raised.
740781

741-
.. code-block:: python
782+
.. code-block:: ipython
783+
784+
In [9]: df3 = pd.DataFrame({'A' : np.arange(6),
785+
'B' : pd.Series(list('aabbca')).astype('category')})
742786
743-
>>> df3 = pd.DataFrame({'A': np.arange(6),
744-
... 'B': pd.Series(list('aabbca')).astype('category')})
745-
>>> df3 = df3.set_index('B')
746-
>>> df3.index
747-
CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'], categories=[u'a', u'b', u'c'], ordered=False, name=u'B', dtype='category')
787+
In [11]: df3 = df3.set_index('B')
748788
749-
>>> pd.concat([df2, df3])
789+
In [11]: df3.index
790+
Out[11]: CategoricalIndex([u'a', u'a', u'b', u'b', u'c', u'a'], categories=[u'a', u'b', u'c'], ordered=False, name=u'B', dtype='category')
791+
792+
In [12]: pd.concat([df2, df3]
750793
TypeError: categories must match existing categories when appending
751794
752795
.. _indexing.rangeindex:
@@ -1028,14 +1071,14 @@ On the other hand, if the index is not monotonic, then both slice bounds must be
10281071
# OK because 2 and 4 are in the index
10291072
df.loc[2:4, :]
10301073
1031-
.. code-block:: python
1074+
.. code-block:: ipython
10321075
10331076
# 0 is not in the index
1034-
>>> df.loc[0:4, :]
1077+
In [9]: df.loc[0:4, :]
10351078
KeyError: 0
10361079
10371080
# 3 is not a unique label
1038-
>>> df.loc[2:3, :]
1081+
In [11]: df.loc[2:3, :]
10391082
KeyError: 'Cannot get right slice bound for non-unique label: 3'
10401083
10411084
``Index.is_monotonic_increasing`` and ``Index.is_monotonic_decreasing`` only check that

doc/source/basics.rst

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,23 @@ To evaluate single-element pandas objects in a boolean context, use the method
302302
303303
.. warning::
304304

305-
Using a DataFrame as a condition will raise errors,
306-
as you are trying to compare multiple values:
305+
You might be tempted to do the following:
307306

308307
.. code-block:: python
309308
310-
>>> if df:
311-
... do_something()
312-
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
309+
>>> if df: # noqa: E999
310+
...
311+
312+
Or
313+
314+
.. code-block:: python
315+
316+
>>> df and df2 # noqa: E999
317+
318+
These will both raise errors, as you are trying to compare multiple values.
319+
320+
.. code-block:: console
313321
314-
>>> if df and df2:
315-
... do_something()
316322
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
317323
318324
See :ref:`gotchas<gotchas.truth>` for a more detailed discussion.
@@ -1459,8 +1465,21 @@ for altering the ``Series.name`` attribute.
14591465
14601466
.. _basics.rename_axis:
14611467

1462-
The Panel class has a related :meth:`~Panel.rename_axis` class which can rename
1463-
any of its three axes.
1468+
.. versionadded:: 0.24.0
1469+
1470+
The methods :meth:`~DataFrame.rename_axis` and :meth:`~Series.rename_axis`
1471+
allow specific names of a `MultiIndex` to be changed (as opposed to the
1472+
labels).
1473+
1474+
.. ipython:: python
1475+
1476+
df = pd.DataFrame({'x': [1, 2, 3, 4, 5, 6],
1477+
'y': [10, 20, 30, 40, 50, 60]},
1478+
index=pd.MultiIndex.from_product([['a', 'b', 'c'], [1, 2]],
1479+
names=['let', 'num']))
1480+
df
1481+
df.rename_axis(index={'let': 'abc'})
1482+
df.rename_axis(index=str.upper)
14641483
14651484
.. _basics.iteration:
14661485

doc/source/comparison_with_sas.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ see the :ref:`timeseries documentation<timeseries>` for more details.
298298
.. ipython:: python
299299
:suppress:
300300
301-
tips = tips.drop(['date1', 'date2', 'date1_year', 'date2_month',
302-
'date1_next', 'months_between'], axis=1)
301+
tips = tips.drop(['date1','date2','date1_year',
302+
'date2_month','date1_next','months_between'], axis=1)
303303
304304
Selection of Columns
305305
~~~~~~~~~~~~~~~~~~~~
@@ -744,9 +744,12 @@ XPORT is a relatively limited format and the parsing of it is not as
744744
optimized as some of the other pandas readers. An alternative way
745745
to interop data between SAS and pandas is to serialize to csv.
746746

747-
>>> # version 0.17, 10M rows
748-
>>> %time df = pd.read_sas('big.xpt')
749-
Wall time: 14.6 s
747+
.. code-block:: ipython
750748
751-
>>> %time df = pd.read_csv('big.csv')
752-
Wall time: 4.86 s
749+
# version 0.17, 10M rows
750+
751+
In [8]: %time df = pd.read_sas('big.xpt')
752+
Wall time: 14.6 s
753+
754+
In [9]: %time df = pd.read_csv('big.csv')
755+
Wall time: 4.86 s

doc/source/contributing.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,10 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
783783
assert str(np.dtype(dtype)) == dtype
784784
785785
786-
@pytest.mark.parametrize('dtype',
787-
['float32',
788-
pytest.param('int16', marks=pytest.mark.skip),
789-
pytest.param('int32', marks=pytest.mark.xfail(
790-
reason='example'))
791-
])
786+
@pytest.mark.parametrize(
787+
'dtype', ['float32', pytest.param('int16', marks=pytest.mark.skip),
788+
pytest.param('int32', marks=pytest.mark.xfail(
789+
reason='to show how it works'))])
792790
def test_mark(dtype):
793791
assert str(np.dtype(dtype)) == 'float32'
794792

doc/source/cookbook.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -968,34 +968,37 @@ Parsing date components in multi-columns
968968

969969
Parsing date components in multi-columns is faster with a format
970970

971-
.. code-block::
971+
.. code-block:: ipython
972972
973-
>>> i = pd.date_range('20000101', periods=10000)
974-
>>> df = pd.DataFrame({year: i.year, month: i.month, day: i.day})
975-
>>> df.head()
973+
In [30]: i = pd.date_range('20000101',periods=10000)
974+
975+
In [31]: df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
976+
977+
In [32]: df.head()
978+
Out[32]:
976979
day month year
977980
0 1 1 2000
978981
1 2 1 2000
979982
2 3 1 2000
980983
3 4 1 2000
981984
4 5 1 2000
982985
983-
>>> %timeit pd.to_datetime(df.year * 10000 + df.month * 100 + df.day,
984-
... format='%Y%m%d')
986+
In [33]: %timeit pd.to_datetime(df.year*10000+df.month*100+df.day,format='%Y%m%d')
985987
100 loops, best of 3: 7.08 ms per loop
986988
987989
# simulate combinging into a string, then parsing
988-
>>> ds = df.apply(lambda x: "%04d%02d%02d" %
989-
... (x['year'], x['month'], x['day']), axis=1)
990-
>>> ds.head()
990+
In [34]: ds = df.apply(lambda x: "%04d%02d%02d" % (x['year'],x['month'],x['day']),axis=1)
991+
992+
In [35]: ds.head()
993+
Out[35]:
991994
0 20000101
992995
1 20000102
993996
2 20000103
994997
3 20000104
995998
4 20000105
996999
dtype: object
9971000
998-
>>> %timeit pd.to_datetime(ds)
1001+
In [36]: %timeit pd.to_datetime(ds)
9991002
1 loops, best of 3: 488 ms per loop
10001003
10011004
Skip row between header and data

doc/source/enhancingperf.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,19 @@ Consider the following toy example of doubling each observation:
388388
def double_every_value_withnumba(x):
389389
return x * 2
390390
391+
.. code-block:: ipython
391392
392-
>>> # Custom function without numba
393-
>>> %timeit df['col1_doubled'] = df.a.apply(double_every_value_nonumba)
394-
1000 loops, best of 3: 797 us per loop
393+
# Custom function without numba
394+
In [5]: %timeit df['col1_doubled'] = df.a.apply(double_every_value_nonumba)
395+
1000 loops, best of 3: 797 us per loop
395396
396-
>>> # Standard implementation (faster than a custom function)
397-
>>> %timeit df['col1_doubled'] = df.a*2
398-
1000 loops, best of 3: 233 us per loop
397+
# Standard implementation (faster than a custom function)
398+
In [6]: %timeit df['col1_doubled'] = df.a*2
399+
1000 loops, best of 3: 233 us per loop
399400
400-
>>> # Custom function with numba
401-
>>> %timeit df['col1_doubled'] = double_every_value_withnumba(df.a.values)
402-
1000 loops, best of 3: 145 us per loop
401+
# Custom function with numba
402+
In [7]: %timeit df['col1_doubled'] = double_every_value_withnumba(df.a.values)
403+
1000 loops, best of 3: 145 us per loop
403404
404405
Caveats
405406
~~~~~~~

doc/source/gotchas.rst

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,40 @@ something to a ``bool``. This happens in an ``if``-statement or when using the
9696
boolean operations: ``and``, ``or``, and ``not``. It is not clear what the result
9797
of the following code should be:
9898

99-
>>> if pd.Series([False, True, False]):
100-
... print("I was true")
99+
.. code-block:: python
100+
101+
>>> if pd.Series([False, True, False]): # noqa: E999
102+
...
101103
102104
Should it be ``True`` because it's not zero-length, or ``False`` because there
103105
are ``False`` values? It is unclear, so instead, pandas raises a ``ValueError``:
104106

105-
>>> if pd.Series([False, True, False]):
106-
... print("I was true")
107-
Traceback
108-
...
109-
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
107+
.. code-block:: python
108+
109+
>>> if pd.Series([False, True, False]):
110+
... print("I was true")
111+
Traceback
112+
...
113+
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
110114
111115
You need to explicitly choose what you want to do with the ``DataFrame``, e.g.
112116
use :meth:`~DataFrame.any`, :meth:`~DataFrame.all` or :meth:`~DataFrame.empty`.
113117
Alternatively, you might want to compare if the pandas object is ``None``:
114118

115-
>>> if pd.Series([False, True, False]) is not None:
116-
... print("I was not None")
117-
I was not None
119+
.. code-block:: python
120+
121+
>>> if pd.Series([False, True, False]) is not None:
122+
... print("I was not None")
123+
I was not None
118124
119125
120126
Below is how to check if any of the values are ``True``:
121127

122-
>>> if pd.Series([False, True, False]).any():
123-
... print("I am any")
124-
I am any
128+
.. code-block:: python
129+
130+
>>> if pd.Series([False, True, False]).any():
131+
... print("I am any")
132+
I am any
125133
126134
To evaluate single-element pandas objects in a boolean context, use the method
127135
:meth:`~DataFrame.bool`:

doc/source/groupby.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ object (more on what the GroupBy object is later), you may do the following:
8181

8282
.. code-block:: python
8383
84-
# default is axis=0
85-
>>> grouped = obj.groupby(key)
86-
>>> grouped = obj.groupby(key, axis=1)
87-
>>> grouped = obj.groupby([key1, key2])
84+
# default is axis=0
85+
>>> grouped = obj.groupby(key)
86+
>>> grouped = obj.groupby(key, axis=1)
87+
>>> grouped = obj.groupby([key1, key2])
8888
8989
The mapping can be specified many different ways:
9090

doc/source/io.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,7 +3483,6 @@ This format is specified by default when using ``put`` or ``to_hdf`` or by ``for
34833483
.. code-block:: python
34843484
34853485
>>> pd.DataFrame(randn(10, 2)).to_hdf('test_fixed.h5', 'df')
3486-
34873486
>>> pd.read_hdf('test_fixed.h5', 'df', where='index>5')
34883487
TypeError: cannot pass a where specification when reading a fixed format.
34893488
this store must be selected in its entirety
@@ -3580,13 +3579,14 @@ will yield a tuple for each group key along with the relative keys of its conten
35803579

35813580
Hierarchical keys cannot be retrieved as dotted (attribute) access as described above for items stored under the root node.
35823581

3583-
.. code-block:: python
3582+
.. code-block:: ipython
35843583
3585-
>>> store.foo.bar.bah
3584+
In [8]: store.foo.bar.bah
35863585
AttributeError: 'HDFStore' object has no attribute 'foo'
35873586
35883587
# you can directly access the actual PyTables node but using the root node
3589-
>>> store.root.foo.bar.bah
3588+
In [9]: store.root.foo.bar.bah
3589+
Out[9]:
35903590
/foo/bar/bah (Group) ''
35913591
children := ['block0_items' (Array), 'block0_values' (Array), 'axis0' (Array), 'axis1' (Array)]
35923592
@@ -3737,7 +3737,7 @@ The right-hand side of the sub-expression (after a comparison operator) can be:
37373737
37383738
instead of this
37393739

3740-
.. code-block:: python
3740+
.. code-block:: ipython
37413741
37423742
string = "HolyMoly'"
37433743
store.select('df', 'index == %s' % string)

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ exclude =
2828
doc/temp/*.py,
2929
.eggs/*.py,
3030
versioneer.py
31-
.tox
3231

3332
[flake8-rst]
3433
ignore =

0 commit comments

Comments
 (0)