简体   繁体   English

熊猫:更新其中一个列缺少数据的行的数据框值

[英]Pandas: Updating dataframe values for rows where one colum has missing data

I have a dataframe called firstpart . 我有一个名为firstpart的数据

I'm trying to update the values in one column ( Key ), but only for rows in which another column ( Zone ) has no data. 我正在尝试更新一列( Key )中的值,但仅更新其中另一列( Zone )没有数据的行。

I'm using this code, which doesn't work: 我正在使用此代码,它不起作用:

firstpart.ix[firstpart.Zone ==np.nan,"Key"] = "newvalue" firstpart.ix [firstpart.Zone == np.nan,“ Key”] =“ newvalue”

Neither does this: 这也没有:

firstpart.ix[firstpart.Zone =="","Key"] = "newvalue" firstpart.ix [firstpart.Zone ==“”,“ Key”] =“ newvalue”

Using this syntax I'm able to update values in rows for which Zone has another value, but for some reason not if I try to select the rows in which it is blank. 使用这种语法,我可以更新Zone具有另一个值的行中的值,但是由于某些原因,如果我尝试选择空白的行则无法更新。

What am I doing wrong? 我究竟做错了什么?

firstpart.ix[firstpart.Zone.isnull()] = "newvalue"

You can't equate NaN to anything. 您不能将NaN等同于任何东西。

In [1]: NaN == NaN
Out[1]: False

You need special methods for that, and this is what .isnull() is about. 为此,您需要特殊的方法,这就是.isnull()的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM