dataframe - Pandas: Re-assigning values to a 'block' of a Data frame -


probably trivial problem, need understand what's going on here (and how fix it).

suppose have dataframe columns 'a' , 'b', follows:

f = pandas.dataframe({'a':[1,2,3,4,5], 'b':[10,20,30,40,50]}) 

now every element of 'a' 3 or less, want divide corresponding elements of 'b' 10.

f[f['a']<=3]['b'] = (f[f['a']<=3]['b'])/10 

so values in column 'b' should [1,2,3,40,50].

but find column 'b' remains unchanged! gives?

i think trying assign values copy rather view (f[f['a']<=3]['b'] copy), see returning view versus copy.

however, can reorder , it'll work view:

in [11]: f['b'][f['a']<=3] = (f[f['a']<=3]['b'])/10  in [12]: f out[12]:      b 0  1   1 1  2   2 2  3   3 3  4  40 4  5  50 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -