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
If you got here via `transpose` or an `axis=1` operation, then you should first set an index, e.g.: `df.pipe(lambda _df: _df.set_axis(pd.RangeIndex(len(df))))`
203
+
If you got here via `transpose`or an `axis=1` operation, then you should first set an index, e.g.: `df.pipe(lambda_df: _df.set_axis(pd.RangeIndex(len(_df))))`
202
204
```
203
205
204
206
### DataFrameFormatter and SeriesFormatter changes
@@ -222,21 +224,40 @@ Of the above changes, this may be the only one that would need implementing with
222
224
## Usage and Impact
223
225
224
226
By itself, ``NoRowIndex`` would be of limited use. To become useful and user-friendly,
225
-
a mode ``no_default_index`` could be introduced which, if enabled, would change
227
+
a ``no_default_index`` mode could be introduced which, if enabled, would change
226
228
the ``default_index`` function to return a ``NoRowIndex`` of the appropriate length.
227
229
In particular, ``.reset_index()`` would result in a ``DataFrame`` with a ``NoRowIndex``.
228
230
Likewise, a ``DataFrame`` constructed without explicitly specifying ``index=``.
229
231
230
-
Then, if a user doesn't want to think about row labels, then with ``pd.set_option('no_default_index')``
231
-
set, they wouldn't need to (barring methods such as `.pivot_table` which introduce an index).
232
-
Discussion of such a mode is out-of-scope for this proposal.
232
+
Furthermore, it could be useful to add ``as_index`` options to methods which currently
233
+
set an index, and then allow for that mode to control the ``as_index`` default.
234
+
235
+
Discussion of such a mode is out-of-scope for this proposal. A ``NoRowIndex`` would
236
+
just be a first step towards getting there.
233
237
234
238
## Implementation
235
239
236
240
Draft pull request showing proof of concept: https://github.com/pandas-dev/pandas/pull/49693.
237
241
242
+
Note that implementation details could well change even if this PDEP were
243
+
accepted. For example, ``NoRowIndex`` wouldn't necessarily need to subclass
244
+
``RangeIndex``, and it wouldn't necessarily need to be accessible to the user
245
+
(``df.index`` could well return ``None``)
246
+
238
247
## Likely FAQ
239
248
249
+
**Q: Couldn't users just use ``RangeIndex``? Why do we need a new class?**
250
+
251
+
**A**: ``RangeIndex`` isn't preserved under slicing and appending, e.g.:
252
+
```python
253
+
In [1]: ser = pd.Series([1,2,3])
254
+
255
+
In [2]: ser[ser!=2].index
256
+
Out[2]: Int64Index([0, 2], dtype='int64')
257
+
```
258
+
If someone doesn't want to think about row labels and starts off
259
+
with a ``RangeIndex``, they'll very quickly lose it.
260
+
240
261
**Q: Aren't indices really powerful?**
241
262
242
263
**A:** Yes! And they're also confusing to many users, even experienced developers.
0 commit comments