Try to replace a specific value in a dataframe, but does not overwritte it

前端 未结 1 1316
臣服心动
臣服心动 2021-01-23 15:00

My dataframe looks like this orders_total:

    price   amount  side
0   0.003019    100 bids
0   0.003143    100 asks

When I try t

相关标签:
1条回答
  • 2021-01-23 15:33

    You're attempting to modify in-place when you really are ending up with a copy of the dataframe, not a view, and hence the original dataframe remains unchanged. This is known as chained indexing.

    To find out more on this check: Returning a view versus a copy.

    You want to index along both axis using .loc. This will lead to a single call to __getitem__ which will return a view of the dataframe, and changes to this view will be reflected on the original dataframe:

    orders_total.loc[orders_total.side == 'asks', 'amount'] -= 10
    
    0 讨论(0)
提交回复
热议问题