Last answered:

21 Nov 2023

Posted on:

19 Nov 2023


Future warning on index

It looks like when we declare an explicit index, it will no longer be possible to call the implicit index with the same syntax (example with series_c[1]).

 FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`

instead, use series_c.iloc[1]

1 answers ( 0 marked as helpful)
Posted on:

21 Nov 2023


Hi Frederic!
Thanks for reaching out.

In recent versions of pandas, if you have explicitly set an index for a Series, accessing elements using `series_c[1]` (where `1` is an integer) may generate a FutureWarning. This is because pandas is moving towards a behavior where integers in `[]` will always be interpreted as labels, not positions, to be consistent with DataFrame behavior.

To access elements by position in such cases, you should use `series_c.iloc[1]`. The `.iloc` accessor is specifically designed for position-based indexing, regardless of the index labels.

Hope this helps.

Submit an answer