Skip to content

Wrong slicing behavior for DataFrame loc #14900

Closed
@Ajeet-Ganga

Description

@Ajeet-Ganga

Code Sample, a copy-pastable example if possible

>>> df
   0   1   2   3
0  1  21  51  61
1  2  22  52  62
2  3  23  53  63
>>> df[0:0]
Empty DataFrame
Columns: [0, 1, 2, 3]
Index: []
>>> df.loc[0:0]
   0   1   2   3
0  1  21  51  61

For loc, slicing is incorrect

The behavior exhibited by slicing of loc is incosistent with python array slicing.
For [0:0] it should have returned empty, but it is returning a row.

Expected Output

Similar to code show below for python array, pd.DataFrame.loc slicing should produce empty

E.g. Following code slices empty for [0:0]

>>> l = [0,1,2]
>>> l[0:0]
[]

Output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 25.2.0
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: 2.2.0-b1
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions