Replace value for a selected cell in pandas DataFrame without using index

前端 未结 3 1373
后悔当初
后悔当初 2020-11-29 18:44

this is a rather similar question to this question but with one key difference: I\'m selecting the data I want to change not by its index but by some criteria.

If th

3条回答
  •  -上瘾入骨i
    2020-11-29 19:19

    Not sure about older version of pandas, but in 0.16 the value of a particular cell can be set based on multiple column values.

    Extending the answer provided by @waitingkuo, the same operation can also be done based on values of multiple columns.

    d.loc[(d.day== 'sun') & (d.flavour== 'banana') & (d.year== 2009),'sales'] = 100
    

提交回复
热议问题