将.loc与一列值一起使用

时间:2016-06-14 01:52:19

标签: python numpy pandas dataframe

假设我在数据帧df中有一个列切片,我想用其他浮点值替换浮点值。只有要替换的值来自另一个数据帧`newdf。

我尝试过使用

df.loc[row index condition, [column to replace vals]] = newdf[column]

但由于某种原因,结果值均为NaN。为什么会这样?

1 个答案:

答案 0 :(得分:2)

newdf的值需要与index的{​​{1}}对齐。如果df包含您要插入的确切数值,则可以尝试使用.values

newdf
相关问题