Skip to content

BUG: Index name lost when using .loc with list of indices #8555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jason-curtis opened this issue Oct 14, 2014 · 4 comments
Closed

BUG: Index name lost when using .loc with list of indices #8555

jason-curtis opened this issue Oct 14, 2014 · 4 comments

Comments

@jason-curtis
Copy link

When using DataFrame.loc with a list of indices, the index name is missing from the resultant DataFrame unless the list of indices includes all of the indices in the original DataFrame.

Example:

import pandas as pd
d=pd.DataFrame(
    [
        [1,2,3],
        [4,5,6],
        [7,8,9]
    ], 
    columns=['i','j','k']
).set_index('i')

When I use .loc and ask for all of the rows, I get (as desired) the correct, named index out the other end:

d.loc[[1,4,7]]
#    j  k
# i      
#1  2  3
#4  5  6
#7  8  9

d.loc[[1,4,7]].index.name
# 'i'

When I ask for a list of indices that is not all of them, I also expect to get a named index out the other end. However, the index values are preserved but the index name is lost:

d.loc[[1,4]]
#    j  k
#1  2  3
#4  5  6

d.loc[[1,4]].index.name
# None

Suggesting that this is a bug because the index naming should be the same no matter whether I .loc for for all of the rows or just some of them.

@jason-curtis
Copy link
Author

pd.show_versions() output:

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-24-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.14.0
nose: 1.3.3
Cython: 0.19.1
numpy: 1.8.1
scipy: 0.13.3
statsmodels: 0.5.0
IPython: 2.1.0
sphinx: 1.2.2
patsy: 0.2.1
scikits.timeseries: None
dateutil: 2.2
pytz: 2014.4
bottleneck: None
tables: 3.1.2dev
numexpr: 2.4.1.dev
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
bq: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: 2.4.5 (dt dec mx pq3 ext)

@jreback
Copy link
Contributor

jreback commented Oct 14, 2014

this works in master/0.15 (IIRC fixed for 0.14.1 as well), but don't remember off-hand

try out the rc1

http://pandas.pydata.org/

@jreback jreback closed this as completed Oct 14, 2014
@jason-curtis
Copy link
Author

Never mind then. Thanks!

@immerrr
Copy link
Contributor

immerrr commented Oct 15, 2014

This is a duplicate of #6552, should be fixed in 0.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants