-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Setting value of DataFrame[MultiIndex] via .loc partial indexing fails #22493
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
Comments
That indeed does look a little weird! cc @toobaz |
Not quite sure what is expected here, the align does not work properly with this input.
Setting the MultiIndex for b works
|
b = pd.DataFrame(-1, ['b1', 'b2'], ['c1', 'c2'])
b = pd.DataFrame(-1, pd.MultiIndex.from_product([['a1'], ['b1', 'b2']]), ['c1', 'c2']) @phaebz Here is the difference. While Or from another point of view, |
I get what the difference is. I simply could not find anything in the docs about this, maybe I am missing something. I also got what the problem is. But I am not sure if this is expected. |
No docs mentioned indeed. What should be considered is, whether |
@gfyoung and everybody, sorry for replying after more than two years. I think we can summarize the project stance on assigning by matching on a subset of a I'm also pretty sure there was already an open issue (and I was even involved in it), but I can't find it right now. I remember the Notice that I suspect that it will be very hard to provide a clean fix for these before fixing #12827 , because in some way the code that indexes on subsets of |
The title change is justified by the existence of a relatively easy, although annoying, workaround which does not exploit partial indexing (well, it actually does, but only to determine the destination, not to match indexes):
EDIT: that may seem a more complicated way to do what @phofl did above. But the thing is: that should not work! (oh what a mess) Because |
Another related thing that probably should not work emerged today in the mailing list: In [2]: s = pd.Series(range(9), index=pd.MultiIndex.from_product([list('abc'), list('def')]))
In [3]: mask = s % 2 == 0
In [4]: s.loc['a', mask]
Out[4]:
a d 0
f 2
dtype: int64 ... while |
Code Sample, a copy-pastable example if possible
Problem description
Setting value of
DataFrame
via.loc
withDataFrame
failed, even they have same columns and indexes.Expected Output
Works the same like with
.values
.Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: zh_CN.UTF-8
pandas: 0.23.4
pytest: 3.7.1
pip: 10.0.1
setuptools: 39.2.0
Cython: None
numpy: 1.15.0
scipy: 1.1.0
pyarrow: 0.9.0
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 1.0.5
lxml: 4.2.4
bs4: 4.6.3
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: