Skip to content

DOC: Series.str.slice() should show that negative values for start are allowed #27802

Closed
@Dr-Irv

Description

@Dr-Irv

Code Sample, a copy-pastable example if possible

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '0.25.0'

In [3]: s = pd.Series(["A1", "BC2", "DEF3"])

In [4]: s
Out[4]:
0      A1
1     BC2
2    DEF3
dtype: object

In [5]: s.str.slice(start=-1)
Out[5]:
0    1
1    2
2    3
dtype: object

In [6]: s.str[:-1]
Out[6]:
0      A
1     BC
2    DEF
dtype: object

Problem description

It is not apparent from the documentation at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.slice.html that you can specify negative values for the start and stop arguments. So I think this should be stated, as well as used in some examples (as shown above).

Expected Output

N/A

Output of pd.show_versions()

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions