@@ -304,38 +304,6 @@ largely as a convenience since it is such a common operation.
304
304
Selection By Label
305
305
------------------
306
306
307
- .. warning ::
308
-
309
- Whether a copy or a reference is returned for a setting operation, may depend on the context.
310
- This is sometimes called ``chained assignment `` and should be avoided.
311
- See :ref: `Returning a View versus Copy <indexing.view_versus_copy >`.
312
-
313
- .. warning ::
314
-
315
- ``.loc `` is strict when you present slicers that are not compatible (or convertible) with the index type. For example
316
- using integers in a ``DatetimeIndex ``. These will raise a ``TypeError ``.
317
-
318
- .. ipython :: python
319
-
320
- dfl = pd.DataFrame(np.random.randn(5 ,4 ), columns = list (' ABCD' ), index = pd.date_range(' 20130101' ,periods = 5 ))
321
- dfl
322
-
323
- .. code-block :: ipython
324
-
325
- In [4]: dfl.loc[2:3]
326
- TypeError: cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with these indexers [2] of <type 'int'>
327
-
328
- String likes in slicing *can * be convertible to the type of the index and lead to natural slicing.
329
-
330
- .. ipython :: python
331
-
332
- dfl.loc[' 20130102' :' 20130104' ]
333
-
334
- .. warning ::
335
-
336
- Starting in 0.21.0, pandas will show a ``FutureWarning `` if indexing with a list with missing labels. In the future
337
- this will raise a ``KeyError ``. See :ref: `list-like Using loc with missing keys in a list is Deprecated <indexing.deprecate_loc_reindex_listlike >`.
338
-
339
307
pandas provides a suite of methods in order to have **purely label based indexing **. This is a strict inclusion based protocol.
340
308
Every label asked for must be in the index, or a ``KeyError `` will be raised.
341
309
When slicing, both the start bound **AND ** the stop bound are *included *, if present in the index.
@@ -352,6 +320,12 @@ The ``.loc`` attribute is the primary access method. The following are valid inp
352
320
- A boolean array.
353
321
- A ``callable ``, see :ref: `Selection By Callable <indexing.callable >`.
354
322
323
+ .. warning ::
324
+
325
+ Whether a copy or a reference is returned for a setting operation, may depend on the context.
326
+ This is sometimes called ``chained assignment `` and should be avoided.
327
+ See :ref: `Returning a View versus Copy <indexing.view_versus_copy >`.
328
+
355
329
.. ipython :: python
356
330
357
331
s1 = pd.Series(np.random.randn(6 ),index = list (' abcdef' ))
@@ -402,6 +376,33 @@ For getting a value explicitly (equivalent to deprecated ``df.get_value('a','A')
402
376
# this is also equivalent to ``df1.at['a','A']``
403
377
df1.loc[' a' , ' A' ]
404
378
379
+ .. warning ::
380
+
381
+ ``.loc `` is strict when you present slicers that are not compatible (or convertible) with the index type. For example
382
+ using integers in a ``DatetimeIndex ``. These will raise a ``TypeError ``.
383
+
384
+ .. ipython :: python
385
+
386
+ dfl = pd.DataFrame(np.random.randn(5 ,4 ), columns = list (' ABCD' ),
387
+ index = pd.date_range(' 20130101' ,periods = 5 ))
388
+ dfl
389
+
390
+ .. code-block :: ipython
391
+
392
+ In [4]: dfl.loc[2:3]
393
+ TypeError: cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with these indexers [2] of <type 'int'>
394
+
395
+ String likes in slicing *can * be convertible to the type of the index and lead to natural slicing.
396
+
397
+ .. ipython :: python
398
+
399
+ dfl.loc[' 20130102' :' 20130104' ]
400
+
401
+ .. warning ::
402
+
403
+ Starting in 0.21.0, pandas will show a ``FutureWarning `` if indexing with a list with missing labels. In the future
404
+ this will raise a ``KeyError ``. See :ref: `list-like Using loc with missing keys in a list is Deprecated <indexing.deprecate_loc_reindex_listlike >`.
405
+
405
406
.. _indexing.slicing_with_labels :
406
407
407
408
Slicing with labels
0 commit comments