Skip to content

Tuple-Retrieving vs. -Setting on non-MultiIndex DataFrame #10175

@fabboe

Description

@fabboe
df = pd.DataFrame({'a':[55,66,77],'b':[100,111,112],'ch':['x','y','z']})
df.index = pd.Index([10,11,12])

In [6]: df
Out[6]: 
     a    b ch
10  55  100  x
11  66  111  y
12  77  112  z

In [7]: df.loc[10,('b','ch')]
....
ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'>

In [8]: df.ix[10,('b','ch')]
Out[8]: 100

more or less understandable, probably both should not work though.

but then, using the same indexing, the setting operation works, unpacking the tuple into the correct columns, as one would use the correct list selector df.ix[10,['b','ch']] or df.loc[10,['b','ch']]

In [10]: df.ix[10,('b','ch')] = (200,'i')

In [11]: df
Out[11]: 
     a    b ch
10  55  200  i
11  66  111  y
12  77  112  z

In [12]: df.loc[10,('b','ch')] = (300,'j')

In [13]: df
Out[13]: 
     a    b ch
10  55  300  j
11  66  111  y
12  77  112  z

For .ix setting should throw the same error as for retrieving?
For .loc setting should throw an error as you should expect to set a tuple to a single column?

Is this wanted behavior?

P.S.: New to advanced / multi-index slicing, my searches didn't bring up that very issue despite the fact that all issues around this indexing seem somehow related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndexNested DataData where the values are collections (lists, sets, dicts, objects, etc.).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions