Skip to content

inconsistent behaviour with .ix and setting values #2997

Closed
@jankatins

Description

@jankatins

Using .ix twice and assigning a value as in df.ix[...].ix[...] = b works in the first case and not in the second:

>>> # from http://stackoverflow.com/questions/15200598/partial-update-to-dataframe-with-multi-index-index-with-integer-labels/15213525#15213525
>>> print df
  bucket  start  stop                 date  x1  x2  x3
0     B1      1     1  2000-10-03 00:00:00   2   2   3
1     B1      1     1  2000-01-04 00:00:00   4   3   3
2     B1      1     2  2000-01-03 00:00:00   4   2   3
3     B1      1     2  2000-01-04 00:00:00   6   2   2

>>> df2 = df.set_index(['bucket','start','stop'])

>>> print df2
                                  date  x1  x2  x3
bucket start stop                                 
B1     1     1     2000-10-03 00:00:00   2   2   3
             1     2000-01-04 00:00:00   4   3   3
             2     2000-01-03 00:00:00   4   2   3
             2     2000-01-04 00:00:00   6   2   2

>>> df2.ix[('B1',1,2)].ix[:,'x1'] = 5 #works

>>> print df2
                                  date  x1  x2  x3
bucket start stop                                 
B1     1     1     2000-10-03 00:00:00   2   2   3
             1     2000-01-04 00:00:00   4   3   3
             2     2000-01-03 00:00:00   5   2   3
             2     2000-01-04 00:00:00   5   2   2

>>> df3 = pd.DataFrame(data={"z":[1,2,3,4],"a":["a","b","c","d"],"b":["X","Y","X","Y"], "c":[1,2,3,4],"d":[5,6,7,8]})

>>> df4 = df3.set_index(["z","a"])

>>> print df4
     b  c  d
z a         
1 a  X  1  5
2 b  Y  2  6
3 c  X  3  7
4 d  Y  4  8

>>> df4.ix[1:2,"b":].ix[:,"d"] = 7 # does not work

>>> print df4
     b  c  d
z a         
1 a  X  1  5
2 b  Y  2  6
3 c  X  3  7
4 d  Y  4  8

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions