Skip to content
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

DataFrame.ix drops level of MultiIndex #16143

Closed
rene-rex opened this issue Apr 26, 2017 · 1 comment
Closed

DataFrame.ix drops level of MultiIndex #16143

rene-rex opened this issue Apr 26, 2017 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@rene-rex
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame(columns=["A", "B", "C"])
df.set_index(["A", "B"], inplace=True)
df.ix[("x", "y"), :] = 0

print(df)
print(df.ix[("x", slice(None)), :])
print(df)
Output
     C
A B   
x y  0
   C
B   
y  0
   C
B   
y  0

Problem description

My understanding is that DataFrame.ix is a read-only operation and should not modify the DataFrame. However, in the example above column A is dropped from the index and thus cannot be use anymore.

Expected Output

The unmodified DataFrame. So the last print yields the same output as the first one.

Output of pd.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.8.0-46-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: de_DE.UTF-8 LOCALE: de_DE.UTF-8

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 35.0.0
Cython: None
numpy: 1.12.1
scipy: 0.19.0
statsmodels: None
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None

</details>
@jreback
Copy link
Contributor

jreback commented Apr 26, 2017

this is a duplicate of #13842

yes it shouldn't have side-effects. also note that .ix IS deprecated as of 0.20.0

@jreback jreback closed this as completed Apr 26, 2017
@jreback jreback added Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Apr 26, 2017
@jreback jreback added this to the No action milestone Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants