I've created a Pandas DataFrame
df = DataFrame(index=['A','B','C'], columns=['x','y'])
and got this
x y
A NaN NaN
B NaN NaN
C NaN NaN
Then I want to assign value to particular cell, for example for row 'C' and column 'x'.
I've expected to get such result:
x y
A NaN NaN
B NaN NaN
C 10 NaN
with this code:
df.xs('C')['x'] = 10
but contents of df haven't changed. It's again only NaNs in DataFrame.
Any suggestions?
解决方案
RukTech's answer, df.set_value('C', 'x', 10), is far and away faster than the options I've suggested below. However, it has been slated for deprecation.
Why df.xs('C')['x']=10 does