boolean indexing that can produce a view to a large pandas dataframe?

前端 未结 3 1078
暖寄归人
暖寄归人 2021-02-04 08:52

Got a large dataframe that I want to take slices of (according to multiple boolean criteria), and then modify the entries in those slices in order to change the original datafra

3条回答
  •  不要未来只要你来
    2021-02-04 09:27

    Building off of unutbu's example you could also use the boolean index on df.index like so:

    In [11]: df.ix[df.index[idx]] = 999
    
    In [12]: df
    Out[12]:
          A    B    C
    0     9   23   -6
    1   999  999  999
    2     9   25   -4
    3   999  999  999
    4     9   27   -2
    5   999  999  999
    6     9   29    0
    7    10   30    1
    8     9   31    2
    9    10   32    3
    10    9   33    4
    11   10   34    5
    

提交回复
热议问题