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
Copy file name to clipboardExpand all lines: doc/source/indexing.rst
+51-18Lines changed: 51 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,8 @@ See the :ref:`MultiIndex / Advanced Indexing <advanced>` for ``MultiIndex`` and
61
61
62
62
See the :ref:`cookbook<cookbook.selection>` for some advanced strategies
63
63
64
+
.. _indexing.choice:
65
+
64
66
Different Choices for Indexing
65
67
------------------------------
66
68
@@ -104,24 +106,13 @@ of multi-axis indexing.
104
106
105
107
See more at :ref:`Selection by Position <indexing.integer>`
106
108
107
-
- ``.ix`` supports mixed integer and label based access. It is primarily label
108
-
based, but will fall back to integer positional access unless the corresponding
109
-
axis is of integer type. ``.ix`` is the most general and will
110
-
support any of the inputs in ``.loc`` and ``.iloc``. ``.ix`` also supports floating point
111
-
label schemes. ``.ix`` is exceptionally useful when dealing with mixed positional
112
-
and label based hierarchical indexes.
113
-
114
-
However, when an axis is integer based, ONLY
115
-
label based access and not positional access is supported.
116
-
Thus, in such cases, it's usually better to be explicit and use ``.iloc`` or ``.loc``.
117
-
118
109
See more at :ref:`Advanced Indexing <advanced>` and :ref:`Advanced
119
110
Hierarchical <advanced.advanced_hierarchical>`.
120
111
121
-
- ``.loc``, ``.iloc``, ``.ix`` and also ``[]`` indexing can accept a ``callable`` as indexer. See more at :ref:`Selection By Callable <indexing.callable>`.
112
+
- ``.loc``, ``.iloc``, and also ``[]`` indexing can accept a ``callable`` as indexer. See more at :ref:`Selection By Callable <indexing.callable>`.
122
113
123
114
Getting values from an object with multi-axes selection uses the following
124
-
notation (using ``.loc`` as an example, but applies to ``.iloc`` and ``.ix`` as
115
+
notation (using ``.loc`` as an example, but applies to ``.iloc`` as
125
116
well). Any of the axes accessors may be the null slice ``:``. Axes left out of
126
117
the specification are assumed to be ``:``. (e.g. ``p.loc['a']`` is equiv to
127
118
``p.loc['a', :, :]``)
@@ -135,6 +126,48 @@ the specification are assumed to be ``:``. (e.g. ``p.loc['a']`` is equiv to
Startin in 0.20.0, the ``.ix`` indexer is deprecated, in favor of the more strict ``.iloc`` and ``.loc`` indexers. ``.ix`` offers a lot of magic on the inference of what the user wants to do. To wit, ``.ix`` can decide to index *positionally* OR via *labels*. This has caused quite a bit of user confusion over the years.
137
+
138
+
139
+
The recommended methods of indexing are:
140
+
141
+
.. ipython:: python
142
+
143
+
dfd = pd.DataFrame({'A': [1, 2, 3],
144
+
'B': [4, 5, 6]},
145
+
index=list('abc'))
146
+
147
+
dfd
148
+
149
+
Previous Behavior, where you wish to get the 0th and the 2nd elements from the index in the 'A' column.
150
+
151
+
.. code-block:: ipython
152
+
153
+
In [3]: dfd.ix[[0, 2], 'A']
154
+
Out[3]:
155
+
a 1
156
+
c 3
157
+
Name: A, dtype: int64
158
+
159
+
Using ``.loc``. Here we will select the appropriate indexes from the index, then use *label* indexing.
160
+
161
+
.. ipython:: python
162
+
163
+
dfd.loc[df.index[[0, 2]], 'A']
164
+
165
+
Using ``.iloc``. Here we will get the location of the 'A' column, then use *positional* indexing to select things.
166
+
167
+
.. ipython:: python
168
+
169
+
dfd.iloc[[0, 2], df.columns.get_loc('A')]
170
+
138
171
.. _indexing.basics:
139
172
140
173
Basics
@@ -193,7 +226,7 @@ columns.
193
226
194
227
.. warning::
195
228
196
-
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``, ``.iloc`` and ``.ix``.
229
+
pandas aligns all AXES when setting ``Series`` and ``DataFrame`` from ``.loc``, and ``.iloc``.
197
230
198
231
This will **not** modify ``df`` because the column alignment is before value assignment.
199
232
@@ -526,7 +559,7 @@ Selection By Callable
526
559
527
560
.. versionadded:: 0.18.1
528
561
529
-
``.loc``, ``.iloc``, ``.ix`` and also ``[]`` indexing can accept a ``callable`` as indexer.
562
+
``.loc``, ``.iloc``, and also ``[]`` indexing can accept a ``callable`` as indexer.
530
563
The ``callable`` must be a function with one argument (the calling Series, DataFrame or Panel) and that returns valid output for indexing.
531
564
532
565
.. ipython:: python
@@ -641,7 +674,7 @@ Setting With Enlargement
641
674
642
675
.. versionadded:: 0.13
643
676
644
-
The ``.loc/.ix/[]`` operations can perform enlargement when setting a non-existant key for that axis.
677
+
The ``.loc/[]`` operations can perform enlargement when setting a non-existant key for that axis.
645
678
646
679
In the ``Series`` case this is effectively an appending operation
647
680
@@ -906,7 +939,7 @@ without creating a copy:
906
939
907
940
Furthermore, ``where`` aligns the input boolean condition (ndarray or DataFrame),
908
941
such that partial selection with setting is possible. This is analogous to
909
-
partial setting via ``.ix`` (but on the contents rather than the axis labels)
942
+
partial setting via ``.loc`` (but on the contents rather than the axis labels)
910
943
911
944
.. ipython:: python
912
945
@@ -1716,7 +1749,7 @@ A chained assignment can also crop up in setting in a mixed dtype frame.
1716
1749
1717
1750
.. note::
1718
1751
1719
-
These setting rules apply to all of ``.loc/.iloc/.ix``
1752
+
These setting rules apply to all of ``.loc/.iloc``
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.20.0.txt
+48Lines changed: 48 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ users upgrade to this version.
10
10
Highlights include:
11
11
12
12
- Building pandas for development now requires ``cython >= 0.23`` (:issue:`14831`)
13
+
- The ``.ix`` indexer has been deprecated, see :ref:`here <whatsnew.api_breaking.deprecate_ix>`
13
14
14
15
Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations <whatsnew_0200.deprecations>` before updating.
15
16
@@ -122,6 +123,53 @@ Other enhancements
122
123
Backwards incompatible API changes
123
124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
125
126
+
127
+
.. _whatsnew.api_breaking.deprecate_ix
128
+
129
+
Deprecate .ix
130
+
^^^^^^^^^^^^^
131
+
132
+
The ``.ix`` indexer is deprecated, in favor of the more strict ``.iloc`` and ``.loc`` indexers. ``.ix`` offers a lot of magic on the inference of what the user wants to do. To wit, ``.ix`` can decide to index *positionally* OR via *labels*. This has caused quite a bit of user confusion over the years. The full indexing documentation are :ref:`here <indexing>`. (:issue:`14218`)
133
+
134
+
135
+
The recommended methods of indexing are:
136
+
137
+
- ``.loc`` if you want to *label* index
138
+
- ``.iloc`` if you want to *positionally* index.
139
+
140
+
Using ``.ix`` will now show a deprecation warning with a mini-example of how to convert code.
141
+
142
+
.. ipython:: python
143
+
144
+
df = pd.DataFrame({'A': [1, 2, 3],
145
+
'B': [4, 5, 6]},
146
+
index=list('abc'))
147
+
148
+
df
149
+
150
+
Previous Behavior, where you wish to get the 0th and the 2nd elements from the index in the 'A' column.
151
+
152
+
.. code-block:: ipython
153
+
154
+
In [3]: df.ix[[0, 2], 'A']
155
+
Out[3]:
156
+
a 1
157
+
c 3
158
+
Name: A, dtype: int64
159
+
160
+
Using ``.loc``. Here we will select the appropriate indexes from the index, then use *label* indexing.
161
+
162
+
.. ipython:: python
163
+
164
+
df.loc[df.index[[0, 2]], 'A']
165
+
166
+
Using ``.iloc``. Here we will get the location of the 'A' column, then use *positional* indexing to select things.
0 commit comments