Skip to content

Setting values with multiindex .loc #18223

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
jongmmm opened this issue Nov 10, 2017 · 3 comments
Closed

Setting values with multiindex .loc #18223

jongmmm opened this issue Nov 10, 2017 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@jongmmm
Copy link

jongmmm commented Nov 10, 2017

Code Sample

df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
df = df.stack()
df.loc[0] = [0,0]

This returns

In [27]: df
Out[27]:
0  A    0
   B    0
1  A    2
   B    5
2  A    3
   B    6
dtype: int64

Then, if I try

df.loc[0] = df.loc[1]

I get

In [29]: df
Out[29]:
0  A    NaN
   B    NaN
1  A    2.0
   B    5.0
2  A    3.0
   B    6.0
dtype: float64

Expected Output

It should either raise an exception/warning, or produce the same result with df.loc[0] = df.loc[1].values.

@jreback
Copy link
Contributor

jreback commented Nov 11, 2017

duplicate of #10440

a PR to fix is welcome. This should just work, but as lots of issues related to MultiIndex setting, so would welcome some help here.

@jreback jreback closed this as completed Nov 11, 2017
@jreback
Copy link
Contributor

jreback commented Nov 11, 2017

cc @toobaz

@jreback jreback added Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Nov 11, 2017
@jreback jreback added this to the No action milestone Nov 11, 2017
@toobaz
Copy link
Member

toobaz commented Nov 12, 2017

Yes, it is also related to #12313, which is basically the same problem when the MultiIndex is on the columns, rather than on the rows. I'm pretty sure we want to support this eventually, but might take time.

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

3 participants