You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: cannot do slice indexing on <class'pandas.tseries.index.DatetimeIndex'>with these indexers [2] of <type'int'>
309
+
310
+
String likes in slicing *can* be convertible to the type of the index and lead to natural slicing.
311
+
312
+
.. ipython:: python
313
+
314
+
dfl.loc['20130102':'20130104']
315
+
295
316
pandas provides a suite of methods in order to have **purely label based indexing**. This is a strict inclusion based protocol.
296
317
**at least 1** of the labels for which you ask, must be in the index or a ``KeyError`` will be raised! When slicing, the start bound is *included*, **AND** the stop bound is *included*. Integers are valid labels, but they refer to the label **and not the position**.
297
318
@@ -1486,5 +1507,3 @@ This will **not** work at all, and so should be avoided
1486
1507
The chained assignment warnings / exceptions are aiming to inform the user of a possibly invalid
1487
1508
assignment. There may be false positives; situations where a chained assignment is inadvertantly
``isupper()``, ``istitle()`` which behave as the same as standard ``str`` (:issue:`9282`)
46
+
47
+
- Added ``StringMethods.find()`` and ``rfind()`` which behave as the same as standard ``str`` (:issue:`9386`)
48
+
49
+
- ``Index.get_indexer`` now supports ``method='pad'`` and ``method='backfill'`` even for any target array, not just monotonic targets. These methods also work for monotonic decreasing as well as monotonic increasing indexes (:issue:`9258`).
50
+
- ``Index.asof`` now works on all index types (:issue:`9258`).
51
+
52
+
- Added ``StringMethods.isnumeric`` and ``isdecimal`` which behave as the same as standard ``str`` (:issue:`9439`)
53
+
- The ``read_excel()`` function's :ref:`sheetname <_io.specifying_sheets>` argument now accepts a list and ``None``, to get multiple or all sheets respectively. If more than one sheet is specified, a dictionary is returned. (:issue:`9450`)
54
+
55
+
.. code-block:: python
56
+
57
+
# Returns the 1st and 4th sheet, as a dictionary of DataFrames.
- A ``verbose`` argument has been augmented in ``io.read_excel()``, defaults to False. Set to True to print sheet names as they are parsed. (:issue:`9450`)
61
+
- Added ``StringMethods.ljust()`` and ``rjust()`` which behave as the same as standard ``str`` (:issue:`9352`)
62
+
- ``StringMethods.pad()`` and ``center()`` now accept ``fillchar`` option to specify filling character (:issue:`9352`)
63
+
- Added ``StringMethods.zfill()`` which behave as the same as standard ``str`` (:issue:`9387`)
64
+
65
+
DataFrame Assign
66
+
~~~~~~~~~~~~~~~~
67
+
68
+
.. _whatsnew_0160.enhancements.assign:
33
69
34
70
Inspired by `dplyr's
35
71
<http://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html#mutate>`__ ``mutate`` verb, DataFrame has a new
@@ -71,6 +107,55 @@ calculate the ratio, and plot
71
107
72
108
See the :ref:`documentation <dsintro.chained_assignment>` for more. (:issue:`9229`)
73
109
110
+
111
+
Interaction with scipy.sparse
112
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
+
114
+
.. _whatsnew_0160.enhancements.sparse:
115
+
116
+
Added :meth:`SparseSeries.to_coo` and :meth:`SparseSeries.from_coo` methods (:issue:`8048`) for converting to and from ``scipy.sparse.coo_matrix`` instances (see :ref:`here <sparse.scipysparse>`). For example, given a SparseSeries with MultiIndex we can convert to a `scipy.sparse.coo_matrix` by specifying the row and column labels as index levels:
117
+
118
+
.. ipython:: python
119
+
120
+
from numpy import nan
121
+
s = Series([3.0, nan, 1.0, 3.0, nan, nan])
122
+
s.index = MultiIndex.from_tuples([(1, 2, 'a', 0),
123
+
(1, 2, 'a', 1),
124
+
(1, 1, 'b', 0),
125
+
(1, 1, 'b', 1),
126
+
(2, 1, 'b', 0),
127
+
(2, 1, 'b', 1)],
128
+
names=['A', 'B', 'C', 'D'])
129
+
130
+
s
131
+
132
+
# SparseSeries
133
+
ss = s.to_sparse()
134
+
ss
135
+
136
+
A, rows, columns = ss.to_coo(row_levels=['A', 'B'],
137
+
column_levels=['C', 'D'],
138
+
sort_labels=False)
139
+
140
+
A
141
+
A.todense()
142
+
rows
143
+
columns
144
+
145
+
The from_coo method is a convenience method for creating a ``SparseSeries``
@@ -211,96 +296,80 @@ Backwards incompatible API changes
211
296
p // 0
212
297
213
298
299
+
Indexing Changes
300
+
~~~~~~~~~~~~~~~~
214
301
215
-
Deprecations
216
-
~~~~~~~~~~~~
302
+
.. _whatsnew_0160.api_breaking.indexing:
217
303
218
-
.. _whatsnew_0160.deprecations:
304
+
The behavior of a small sub-set of edge cases for using ``.loc`` have changed (:issue:`8613`). Furthermore we have improved the content of the error messages that are raised:
219
305
306
+
- slicing with ``.loc`` where the start and/or stop bound is not found in the index is now allowed; this previously would raise a ``KeyError``. This makes the behavior the same as ``.ix`` in this case. This change is only for slicing, not when indexing with a single label.
``isupper()``, ``istitle()`` which behave as the same as standard ``str`` (:issue:`9282`)
317
+
.. code-block:: python
238
318
239
-
- Added ``StringMethods.find()`` and ``rfind()`` which behave as the same as standard ``str`` (:issue:`9386`)
319
+
In [4]: df.loc['2013-01-02':'2013-01-10']
320
+
KeyError: 'stop bound [2013-01-10] is not in the [index]'
240
321
241
-
- ``Index.get_indexer`` now supports ``method='pad'`` and ``method='backfill'`` even for any target array, not just monotonic targets. These methods also work for monotonic decreasing as well as monotonic increasing indexes (:issue:`9258`).
242
-
- ``Index.asof`` now works on all index types (:issue:`9258`).
322
+
In [6]: s.loc[-10:3]
323
+
KeyError: 'start bound [-10] is not the [index]'
243
324
244
-
- Added ``StringMethods.isnumeric`` and ``isdecimal`` which behave as the same as standard ``str`` (:issue:`9439`)
245
-
- The ``read_excel()`` function's :ref:`sheetname <_io.specifying_sheets>` argument now accepts a list and ``None``, to get multiple or all sheets respectively. If more than one sheet is specified, a dictionary is returned. (:issue:`9450`)
325
+
New Behavior
326
+
327
+
.. ipython:: python
328
+
329
+
df.loc['2013-01-02':'2013-01-10']
330
+
s.loc[-10:3]
331
+
332
+
- allow slicing with float-like values on an integer index for ``.ix``. Previously this was only enabled for ``.loc``:
246
333
247
334
.. code-block:: python
248
335
249
-
# Returns the 1st and 4th sheet, as a dictionary of DataFrames.
- A ``verbose`` argument has been augmented in ``io.read_excel()``, defaults to False. Set to True to print sheet names as they are parsed. (:issue:`9450`)
253
-
- Added ``StringMethods.ljust()`` and ``rjust()`` which behave as the same as standard ``str`` (:issue:`9352`)
254
-
- ``StringMethods.pad()`` and ``center()`` now accept ``fillchar`` option to specify filling character (:issue:`9352`)
255
-
- Added ``StringMethods.zfill()`` which behave as the same as standard ``str`` (:issue:`9387`)
338
+
In [8]: s.ix[-1.0:2]
339
+
TypeError: the slice start value [-1.0] is not a proper indexer for this index type (Int64Index)
256
340
257
-
Interaction with scipy.sparse
258
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341
+
New Behavior
259
342
260
-
.. _whatsnew_0160.enhancements.sparse:
343
+
.. ipython:: python
261
344
262
-
Added :meth:`SparseSeries.to_coo` and :meth:`SparseSeries.from_coo` methods (:issue:`8048`) for converting to and from ``scipy.sparse.coo_matrix`` instances (see :ref:`here <sparse.scipysparse>`). For example, given a SparseSeries with MultiIndex we can convert to a `scipy.sparse.coo_matrix` by specifying the row and column labels as index levels:
345
+
In [8]: s.ix[-1.0:2]
346
+
Out[2]:
347
+
-1 1
348
+
1 2
349
+
2 3
350
+
dtype: int64
263
351
264
-
.. ipython:: python
352
+
- provide a useful exception for indexing with an invalid type for that index when using ``.loc``. For example trying to use ``.loc`` on an index of type ``DatetimeIndex`` or ``PeriodIndex`` or ``TimedeltaIndex``, with an integer (or a float).
265
353
266
-
from numpy import nan
267
-
s = Series([3.0, nan, 1.0, 3.0, nan, nan])
268
-
s.index = MultiIndex.from_tuples([(1, 2, 'a', 0),
269
-
(1, 2, 'a', 1),
270
-
(1, 1, 'b', 0),
271
-
(1, 1, 'b', 1),
272
-
(2, 1, 'b', 0),
273
-
(2, 1, 'b', 1)],
274
-
names=['A', 'B', 'C', 'D'])
354
+
Previous Behavior
275
355
276
-
s
356
+
.. code-block:: python
277
357
278
-
# SparseSeries
279
-
ss = s.to_sparse()
280
-
ss
358
+
In [4]: df.loc[2:3]
359
+
KeyError: 'start bound [2] is not the [index]'
281
360
282
-
A, rows, columns = ss.to_coo(row_levels=['A', 'B'],
283
-
column_levels=['C', 'D'],
284
-
sort_labels=False)
361
+
New Behavior
285
362
286
-
A
287
-
A.todense()
288
-
rows
289
-
columns
363
+
.. code-block:: python
290
364
291
-
The from_coo method is a convenience method for creating a ``SparseSeries``
292
-
from a ``scipy.sparse.coo_matrix``:
365
+
In [4]: df.loc[2:3]
366
+
TypeError: Cannot do slice indexing on <class 'pandas.tseries.index.DatetimeIndex'> with <type 'int'> keys
0 commit comments