Skip to content

Commit ef845af

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into opprep
2 parents c3d9d9f + 5bb5e33 commit ef845af

39 files changed

+1390
-1215
lines changed

ci/requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pytest>=3.1
77
python-dateutil>=2.5.0
88
pytz
99
setuptools>=3.3
10-
sphinx
10+
sphinx=1.5*

doc/source/advanced.rst

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ of the index is up to you:
113113
pd.DataFrame(np.random.randn(6, 6), index=index[:6], columns=index[:6])
114114
115115
We've "sparsified" the higher levels of the indexes to make the console output a
116-
bit easier on the eyes.
116+
bit easier on the eyes. Note that how the index is displayed can be controlled using the
117+
``multi_sparse`` option in ``pandas.set_options()``:
118+
119+
.. ipython:: python
120+
121+
with pd.option_context('display.multi_sparse', False):
122+
df
117123
118124
It's worth keeping in mind that there's nothing preventing you from using
119125
tuples as atomic labels on an axis:
@@ -129,15 +135,6 @@ can find yourself working with hierarchically-indexed data without creating a
129135
``MultiIndex`` explicitly yourself. However, when loading data from a file, you
130136
may wish to generate your own ``MultiIndex`` when preparing the data set.
131137

132-
Note that how the index is displayed by be controlled using the
133-
``multi_sparse`` option in ``pandas.set_options()``:
134-
135-
.. ipython:: python
136-
137-
pd.set_option('display.multi_sparse', False)
138-
df
139-
pd.set_option('display.multi_sparse', True)
140-
141138
.. _advanced.get_level_values:
142139

143140
Reconstructing the level labels
@@ -180,14 +177,13 @@ For example:
180177

181178
.. ipython:: python
182179
183-
  # original MultiIndex
184-
  df.columns
180+
  df.columns # original MultiIndex
185181
186-
# sliced
187-
df[['foo','qux']].columns
182+
df[['foo','qux']].columns # sliced
188183
189184
This is done to avoid a recomputation of the levels in order to make slicing
190-
highly performant. If you want to see the actual used levels.
185+
highly performant. If you want to see only the used levels, you can use the
186+
:func:`MultiIndex.get_level_values` method.
191187

192188
.. ipython:: python
193189
@@ -196,7 +192,7 @@ highly performant. If you want to see the actual used levels.
196192
# for a specific level
197193
df[['foo','qux']].columns.get_level_values(0)
198194
199-
To reconstruct the ``MultiIndex`` with only the used levels, the
195+
To reconstruct the ``MultiIndex`` with only the used levels, the
200196
``remove_unused_levels`` method may be used.
201197

202198
.. versionadded:: 0.20.0
@@ -231,15 +227,33 @@ Advanced indexing with hierarchical index
231227
-----------------------------------------
232228

233229
Syntactically integrating ``MultiIndex`` in advanced indexing with ``.loc`` is a
234-
bit challenging, but we've made every effort to do so. For example the
235-
following works as you would expect:
230+
bit challenging, but we've made every effort to do so. In general, MultiIndex
231+
keys take the form of tuples. For example, the following works as you would expect:
236232

237233
.. ipython:: python
238234
239235
df = df.T
240236
df
241-
df.loc['bar']
242-
df.loc['bar', 'two']
237+
df.loc[('bar', 'two'),]
238+
239+
Note that ``df.loc['bar', 'two']`` would also work in this example, but this shorthand
240+
notation can lead to ambiguity in general.
241+
242+
If you also want to index a specific column with ``.loc``, you must use a tuple
243+
like this:
244+
245+
.. ipython:: python
246+
247+
df.loc[('bar', 'two'), 'A']
248+
249+
You don't have to specify all levels of the ``MultiIndex`` by passing only the
250+
first elements of the tuple. For example, you can use "partial" indexing to
251+
get all elements with ``bar`` in the first level as follows:
252+
253+
df.loc['bar']
254+
255+
This is a shortcut for the slightly more verbose notation ``df.loc[('bar',),]`` (equivalent
256+
to ``df.loc['bar',]`` in this example).
243257

244258
"Partial" slicing also works quite nicely.
245259

@@ -260,6 +274,24 @@ Passing a list of labels or tuples works similar to reindexing:
260274
261275
df.loc[[('bar', 'two'), ('qux', 'one')]]
262276
277+
.. info::
278+
279+
It is important to note that tuples and lists are not treated identically
280+
in pandas when it comes to indexing. Whereas a tuple is interpreted as one
281+
multi-level key, a list is used to specify several keys. Or in other words,
282+
tuples go horizontally (traversing levels), lists go vertically (scanning levels).
283+
284+
Importantly, a list of tuples indexes several complete ``MultiIndex`` keys,
285+
whereas a tuple of lists refer to several values within a level:
286+
287+
.. ipython:: python
288+
289+
s = pd.Series([1, 2, 3, 4, 5, 6],
290+
index=pd.MultiIndex.from_product([["A", "B"], ["c", "d", "e"]]))
291+
s.loc[[("A", "c"), ("B", "d")]] # list of tuples
292+
s.loc[(["A", "B"], ["c", "d"])] # tuple of lists
293+
294+
263295
.. _advanced.mi_slicers:
264296

265297
Using slicers
@@ -317,7 +349,7 @@ Basic multi-index slicing using slices, lists, and labels.
317349
dfmi.loc[(slice('A1','A3'), slice(None), ['C1', 'C3']), :]
318350
319351
320-
You can use :class:`pandas.IndexSlice` to facilitate a more natural syntax
352+
You can use :class:`pandas.IndexSlice` to facilitate a more natural syntax
321353
using ``:``, rather than using ``slice(None)``.
322354

323355
.. ipython:: python
@@ -626,7 +658,7 @@ Index Types
626658
-----------
627659

628660
We have discussed ``MultiIndex`` in the previous sections pretty extensively. ``DatetimeIndex`` and ``PeriodIndex``
629-
are shown :ref:`here <timeseries.overview>`, and information about
661+
are shown :ref:`here <timeseries.overview>`, and information about
630662
`TimedeltaIndex`` is found :ref:`here <timedeltas.timedeltas>`.
631663

632664
In the following sub-sections we will highlight some other index types.
@@ -671,9 +703,9 @@ The ``CategoricalIndex`` is **preserved** after indexing:
671703
672704
df2.loc['a'].index
673705
674-
Sorting the index will sort by the order of the categories (Recall that we
675-
created the index with ``CategoricalDtype(list('cab'))``, so the sorted
676-
order is ``cab``.).
706+
Sorting the index will sort by the order of the categories (recall that we
707+
created the index with ``CategoricalDtype(list('cab'))``, so the sorted
708+
order is ``cab``).
677709

678710
.. ipython:: python
679711
@@ -726,7 +758,7 @@ Int64Index and RangeIndex
726758
727759
Indexing on an integer-based Index with floats has been clarified in 0.18.0, for a summary of the changes, see :ref:`here <whatsnew_0180.float_indexers>`.
728760
729-
``Int64Index`` is a fundamental basic index in pandas.
761+
``Int64Index`` is a fundamental basic index in pandas.
730762
This is an Immutable array implementing an ordered, sliceable set.
731763
Prior to 0.18.0, the ``Int64Index`` would provide the default index for all ``NDFrame`` objects.
732764
@@ -765,7 +797,7 @@ The only positional indexing is via ``iloc``.
765797
sf.iloc[3]
766798
767799
A scalar index that is not found will raise a ``KeyError``.
768-
Slicing is primarily on the values of the index when using ``[],ix,loc``, and
800+
Slicing is primarily on the values of the index when using ``[],ix,loc``, and
769801
**always** positional when using ``iloc``. The exception is when the slice is
770802
boolean, in which case it will always be positional.
771803

doc/source/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,8 @@ The following methods are available only for ``SeriesGroupBy`` objects.
22402240
SeriesGroupBy.nunique
22412241
SeriesGroupBy.unique
22422242
SeriesGroupBy.value_counts
2243+
SeriesGroupBy.is_monotonic_increasing
2244+
SeriesGroupBy.is_monotonic_decreasing
22432245

22442246
The following methods are available only for ``DataFrameGroupBy`` objects.
22452247

doc/source/tutorials.rst

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,52 @@ This is a guide to many pandas tutorials, geared mainly for new users.
99
Internal Guides
1010
---------------
1111

12-
pandas own :ref:`10 Minutes to pandas<10min>`
12+
pandas' own :ref:`10 Minutes to pandas<10min>`.
1313

14-
More complex recipes are in the :ref:`Cookbook<cookbook>`
14+
More complex recipes are in the :ref:`Cookbook<cookbook>`.
1515

1616
pandas Cookbook
1717
---------------
1818

19-
The goal of this cookbook (by `Julia Evans <http://jvns.ca>`_) is to
19+
The goal of this 2015 cookbook (by `Julia Evans <http://jvns.ca>`_) is to
2020
give you some concrete examples for getting started with pandas. These
2121
are examples with real-world data, and all the bugs and weirdness that
2222
entails.
2323

24-
Here are links to the v0.1 release. For an up-to-date table of contents, see the `pandas-cookbook GitHub
24+
Here are links to the v0.2 release. For an up-to-date table of contents, see the `pandas-cookbook GitHub
2525
repository <http://github.com/jvns/pandas-cookbook>`_. To run the examples in this tutorial, you'll need to
2626
clone the GitHub repository and get IPython Notebook running.
2727
See `How to use this cookbook <https://github.com/jvns/pandas-cookbook#how-to-use-this-cookbook>`_.
2828

29-
- `A quick tour of the IPython Notebook: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/A%20quick%20tour%20of%20IPython%20Notebook.ipynb>`_
29+
- `A quick tour of the IPython Notebook: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/A%20quick%20tour%20of%20IPython%20Notebook.ipynb>`_
3030
Shows off IPython's awesome tab completion and magic functions.
31-
- `Chapter 1: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%201%20-%20Reading%20from%20a%20CSV.ipynb>`_
31+
- `Chapter 1: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%201%20-%20Reading%20from%20a%20CSV.ipynb>`_
3232
Reading your data into pandas is pretty much the easiest thing. Even
3333
when the encoding is wrong!
34-
- `Chapter 2: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%202%20-%20Selecting%20data%20&%20finding%20the%20most%20common%20complaint%20type.ipynb>`_
34+
- `Chapter 2: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%202%20-%20Selecting%20data%20&%20finding%20the%20most%20common%20complaint%20type.ipynb>`_
3535
It's not totally obvious how to select data from a pandas dataframe.
3636
Here we explain the basics (how to take slices and get columns)
37-
- `Chapter 3: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%203%20-%20Which%20borough%20has%20the%20most%20noise%20complaints%3F%20%28or%2C%20more%20selecting%20data%29.ipynb>`_
37+
- `Chapter 3: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%203%20-%20Which%20borough%20has%20the%20most%20noise%20complaints%3F%20%28or%2C%20more%20selecting%20data%29.ipynb>`_
3838
Here we get into serious slicing and dicing and learn how to filter
3939
dataframes in complicated ways, really fast.
40-
- `Chapter 4: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%204%20-%20Find%20out%20on%20which%20weekday%20people%20bike%20the%20most%20with%20groupby%20and%20aggregate.ipynb>`_
40+
- `Chapter 4: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%204%20-%20Find%20out%20on%20which%20weekday%20people%20bike%20the%20most%20with%20groupby%20and%20aggregate.ipynb>`_
4141
Groupby/aggregate is seriously my favorite thing about pandas
4242
and I use it all the time. You should probably read this.
43-
- `Chapter 5: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%205%20-%20Combining%20dataframes%20and%20scraping%20Canadian%20weather%20data.ipynb>`_
43+
- `Chapter 5: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%205%20-%20Combining%20dataframes%20and%20scraping%20Canadian%20weather%20data.ipynb>`_
4444
Here you get to find out if it's cold in Montreal in the winter
4545
(spoiler: yes). Web scraping with pandas is fun! Here we combine dataframes.
46-
- `Chapter 6: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%206%20-%20String%20operations%21%20Which%20month%20was%20the%20snowiest%3F.ipynb>`_
46+
- `Chapter 6: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%206%20-%20String%20operations%21%20Which%20month%20was%20the%20snowiest%3F.ipynb>`_
4747
Strings with pandas are great. It has all these vectorized string
4848
operations and they're the best. We will turn a bunch of strings
4949
containing "Snow" into vectors of numbers in a trice.
50-
- `Chapter 7: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%207%20-%20Cleaning%20up%20messy%20data.ipynb>`_
50+
- `Chapter 7: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%207%20-%20Cleaning%20up%20messy%20data.ipynb>`_
5151
Cleaning up messy data is never a joy, but with pandas it's easier.
52-
- `Chapter 8: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%208%20-%20How%20to%20deal%20with%20timestamps.ipynb>`_
52+
- `Chapter 8: <http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.2/cookbook/Chapter%208%20-%20How%20to%20deal%20with%20timestamps.ipynb>`_
5353
Parsing Unix timestamps is confusing at first but it turns out
5454
to be really easy.
5555

5656

57-
Lessons for New pandas Users
57+
Lessons for new pandas users
5858
----------------------------
5959

6060
For more resources, please visit the main `repository <https://bitbucket.org/hrojas/learn-pandas>`__.
@@ -125,7 +125,7 @@ There are four sections covering selected topics as follows:
125125

126126
.. _tutorial-exercises-new-users:
127127

128-
Exercises for New Users
128+
Exercises for new users
129129
-----------------------
130130
Practice your skills with real data sets and exercises.
131131
For more resources, please visit the main `repository <https://github.com/guipsamora/pandas_exercises>`__.
@@ -152,9 +152,14 @@ For more resources, please visit the main `repository <https://github.com/guipsa
152152

153153
.. _tutorial-modern:
154154

155-
Modern Pandas
155+
Modern pandas
156156
-------------
157157

158+
Tutorial series written in 2016 by
159+
`Tom Augspurger <https://github.com/TomAugspurger>`_.
160+
The source may be found in the GitHub repository
161+
`TomAugspurger/effective-pandas <https://github.com/TomAugspurger/effective-pandas>`_.
162+
158163
- `Modern Pandas <http://tomaugspurger.github.io/modern-1-intro.html>`_
159164
- `Method Chaining <http://tomaugspurger.github.io/method-chaining.html>`_
160165
- `Indexes <http://tomaugspurger.github.io/modern-3-indexes.html>`_
@@ -168,6 +173,20 @@ Excel charts with pandas, vincent and xlsxwriter
168173

169174
- `Using Pandas and XlsxWriter to create Excel charts <https://pandas-xlsxwriter-charts.readthedocs.io/>`_
170175

176+
Video Tutorials
177+
---------------
178+
179+
- `Pandas From The Ground Up <https://www.youtube.com/watch?v=5JnMutdy6Fw>`_
180+
(2015) (2:24)
181+
`GitHub repo <https://github.com/brandon-rhodes/pycon-pandas-tutorial>`_
182+
- `Introduction Into Pandas <https://www.youtube.com/watch?v=-NR-ynQg0YM>`_
183+
(2016) (1:28)
184+
`GitHub repo <https://github.com/chendaniely/2016-pydata-carolinas-pandas>`_
185+
- `Pandas: .head() to .tail() <https://www.youtube.com/watch?v=7vuO9QXDN50>`_
186+
(2016) (1:26)
187+
`GitHub repo <https://github.com/TomAugspurger/pydata-chi-h2t>`_
188+
189+
171190
Various Tutorials
172191
-----------------
173192

doc/source/whatsnew/v0.23.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ Other Enhancements
323323

324324
- ``IntervalIndex.astype`` now supports conversions between subtypes when passed an ``IntervalDtype`` (:issue:`19197`)
325325
- :class:`IntervalIndex` and its associated constructor methods (``from_arrays``, ``from_breaks``, ``from_tuples``) have gained a ``dtype`` parameter (:issue:`19262`)
326+
- Added :func:`SeriesGroupBy.is_monotonic_increasing` and :func:`SeriesGroupBy.is_monotonic_decreasing` (:issue:`17015`)
326327

327328
.. _whatsnew_0230.api_breaking:
328329

@@ -848,3 +849,5 @@ Other
848849
^^^^^
849850

850851
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`)
852+
- Comparisons between :class:`Series` and :class:`Index` would return a ``Series`` with an incorrect name, ignoring the ``Index``'s name attribute (:issue:`19582`)
853+
-

0 commit comments

Comments
 (0)