Set value for particular cell in pandas DataFrame using index

后端 未结 20 1602
野趣味
野趣味 2020-11-22 05:45

I\'ve created a Pandas DataFrame

df = DataFrame(index=[\'A\',\'B\',\'C\'], columns=[\'x\',\'y\'])

and got this

    x    y
A  NaN         


        
20条回答
  •  花落未央
    2020-11-22 06:39

    The recommended way (according to the maintainers) to set a value is:

    df.ix['x','C']=10
    

    Using 'chained indexing' (df['x']['C']) may lead to problems.

    See:

    • https://stackoverflow.com/a/21287235/1579844
    • http://pandas.pydata.org/pandas-docs/dev/indexing.html#indexing-view-versus-copy
    • https://github.com/pydata/pandas/pull/6031

提交回复
热议问题